Hi, as you may know I am wrapping the Qt4 library. Things are going well, but sometimes when the application ends it seg_faults. The problem is that Qt has a light "garbage collection" scheme. Every "QObject" object that you create must has a "parent" object (except toplevels). When the object is deleted, it clean all the mess of its children and so on. Maybe, child objects are beeing killed too soon and the parents can't find them. I am using the with custodian and ward at the constructors, but sometimes I do not create the object. Besides, I suspect that I reference the same C++ object more than one time which might be a problem. Any ideas of what I can do to manage this memory problem? I dropped here the backtrace of one the segfaults. #0 0xb7eda0bd in mallopt () from /lib/tls/libc.so.6 #1 0xb7ed98fb in mallopt () from /lib/tls/libc.so.6 #2 0xb7eda2e6 in mallopt () from /lib/tls/libc.so.6 #3 0xb7ed8f02 in realloc () from /lib/tls/libc.so.6 #4 0xb721739d in qRealloc (ptr=0x821da28, size=512) at global/qglobal.cpp:1098 #5 0xb7232797 in QListData::realloc (this=0x821ba00, alloc=123) at tools/qlistdata.cpp:73 #6 0xb7232ad4 in QListData::prepend (this=0x821ba00) at tools/qlistdata.cpp:115 #7 0xb72c8a2b in QList<int>::prepend (this=0x821ba00, t=@0xbffff480) at qlist.h:408 #8 0xb72c3cac in QConnectionList::remove (this=0x821b9f0, object=0x8266808) at kernel/qobject.cpp:174 #9 0xb72c66b6 in ~QObject (this=0x8266808) at kernel/qobject.cpp:642 #10 0xb72a9e95 in ~QAbstractItemModel (this=0x8266808) at kernel/qabstractitemmodel.cpp:887 #11 0xb72aa4fb in ~QAbstractListModel (this=0x8266808) at kernel/qabstractitemmodel.cpp:1975 #12 0xb79e8139 in ~QListModel (this=0x8266808) at itemviews/qlistwidget.cpp:102 #13 0xb76ab867 in ~QWidget (this=0x8253518) at kernel/qwidget.cpp:898 #14 0xb78c91e7 in ~QFrame (this=0x8253518) at widgets/qframe.cpp:209 #15 0xb7948777 in ~QAbstractScrollArea (this=0x8253518) at widgets/qabstractscrollarea.cpp:209 #16 0xb79a1ed7 in ~QAbstractItemView (this=0x8253518) at itemviews/qabstractitemview.cpp:408 #17 0xb79b445b in ~QListView (this=0x8253518) at itemviews/qlistview.cpp:247 #18 0xb79e4923 in ~QListWidget (this=0x8253518) at itemviews/qlistwidget.cpp:982 #19 0xb76ab093 in ~QWidget (this=0x8240be0) at kernel/qwidget.cpp:898 #20 0xb7d85e92 in ~auto_ptr (this=0xb7de7f2c) at memory:259 #21 0xb7d8694b in ~pointer_holder (this=0xb7de7f24) at pointer_holder.hpp:55 #22 0xb7ccfb2b in boost::python::instance_holder::instance_holder () from /usr/lib/libboost_python-gcc-mt-1_33.so.1.33.0 ... there are more backtraces but are just like "0x000000 in ?? ()" Thanks, [Eric Jardim]
--- Eric Jardim <ericjardim@gmail.com> wrote:
as you may know I am wrapping the Qt4 library.
Things are going well, but sometimes when the application ends it seg_faults.
I cannot answer your question specificly, but I hope this helps: I found "valgrind" invaluable for tracking down memory management problems: http://valgrind.org/ I am not sure how well it works with threaded applications, but it is definitely worth a try. Installation takes only a few seconds (the usual ./configure; make; make install). Cheers, Ralf __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On 29 Jul 2005 at 11:28, Eric Jardim wrote:
The problem is that Qt has a light "garbage collection" scheme. Every "QObject" object that you create must has a "parent" object (except toplevels). When the object is deleted, it clean all the mess of its children and so on.
Maybe, child objects are beeing killed too soon and the parents can't find them. I am using the with custodian and ward at the constructors, but sometimes I do not create the object.
Custodian and ward won't help you here. This is happening because python likes to manage the lifetime of its objects and doesn't know when Qt deletes them from underneath it.
Besides, I suspect that I reference the same C++ object more than one time which might be a problem.
Shouldn't be. BPL refcounts.
Any ideas of what I can do to manage this memory problem? I dropped here the backtrace of one the segfaults.
Make your wrappers hold an auto_ptr to your Qt objects. This works as you'd expect it. Upcall when Qt deletes an object to the python layer so it zeros the auto_ptr so python won't delete anything later. If you want to see it in action, see how TnFOX does it at http://www.nedprod.com/TnFOX/ (get the most recent snapshot). Cheers, Niall
Let's do some "flashback" here: 2005/7/29, Niall Douglas <s_sourceforge@nedprod.com>:
Custodian and ward won't help you here. This is happening because python likes to manage the lifetime of its objects and doesn't know when Qt deletes them from underneath it.
Hmm, so that was the problem. Python didn't notice when some objects where destroyed in C++.
Besides, I suspect that I reference the same C++ object more than one
time which might be a problem.
Shouldn't be. BPL refcounts.
This was other problem. But now is solved. Make your wrappers hold an auto_ptr to your Qt objects. This works as
you'd expect it. Upcall when Qt deletes an object to the python layer so it zeros the auto_ptr so python won't delete anything later. If you want to see it in action, see how TnFOX does it at http://www.nedprod.com/TnFOX/ (get the most recent snapshot).
So, do you think auto_ptr will do the trick. I'll try it. What do you mean by "upcall"? I really did not understood this sentense (sorry). Can you show me one of your classes in TnFOX that acts like QObject class in Qt (parent->child)? Peace, [Eric Jardim]
participants (3)
-
Eric Jardim -
Niall Douglas -
Ralf W. Grosse-Kunstleve