[vtkusers] Delete problems

Dominik Szczerba domi at vision.ee.ethz.ch
Sat Jul 15 05:52:43 EDT 2006


Hi David,

I am fine with the smart pointers, however, this is gdb's output. Please 
let me know if you need additional info (in particular, how do I insert 
a breakpoint in the place you requested?)
regards,
Dominik

Trying to delete object with non-zero reference count.

*** glibc detected *** double free or corruption (!prev): 0x0805e230 ***

Program received signal SIGABRT, Aborted.
[Switching to Thread -1245665600 (LWP 11002)]
0xb5dc67c7 in raise () from /lib/tls/libc.so.6
(gdb) bt
#0  0xb5dc67c7 in raise () from /lib/tls/libc.so.6
#1  0xb5dc806b in abort () from /lib/tls/libc.so.6
#2  0xb5dfd545 in __fsetlocking () from /lib/tls/libc.so.6
#3  0xb5e03b97 in malloc_usable_size () from /lib/tls/libc.so.6
#4  0xb5e04032 in free () from /lib/tls/libc.so.6
#5  0xb5f97b73 in operator delete () from /usr/lib/libstdc++.so.5
#6  0xb6a1795c in vtkPolyData::~vtkPolyData () from 
/home/domi/local/pack/vtk-5.1.cvs/lib/libvtkFiltering.so.5.1
#7  0xb67327a4 in vtkObjectBase::UnRegisterInternal () from 
/home/domi/local/pack/vtk-5.1.cvs/lib/libvtkCommon.so.5.1
#8  0xb6731aaf in vtkObject::UnRegisterInternal () from 
/home/domi/local/pack/vtk-5.1.cvs/lib/libvtkCommon.so.5.1
#9  0xb6932cf1 in vtkDataObject::UnRegister () from 
/home/domi/local/pack/vtk-5.1.cvs/lib/libvtkFiltering.so.5.1
#10 0xb67321cc in vtkObjectBase::Delete () from 
/home/domi/local/pack/vtk-5.1.cvs/lib/libvtkCommon.so.5.1
#11 0x0804a630 in main (argc=2, argv=0xbf9a7f34) at 
/home/domi/projects/vtkViewer/src/vtkViewer.cxx:252


David Cole wrote:
> Can you set a breakpoint on this message in the VTK code and then send 
> the call stack to the list? This means that an object *other* than one 
> that has a legitimate reference to it is actually trying to delete it. 
> Your program is trying to forcibly delete something *prior* to when the 
> last referencer has let go of the object.....
> 
> 
> Dominik Szczerba wrote:
> 
>> Thanks a lot, I am doing all this, still with no success:
>>
>> "Trying to delete object with non-zero reference count."
>>
>> Indeed, if I print the reference count it is never zero. So does the 
>> delete order really not matter? If I can only delete non-zero counted 
>> objects, then I cannot delete anything! Are the children not deleted 
>> automatically or something?
>>
>> regards
>> Dominik
>>
>> David Cole wrote:
>>
>>> Any "New" calls should have corresponding "Delete" calls. Any 
>>> "Register" calls should have corresponding "UnRegister" calls. And 
>>> any reference loops need to be broken by setting one of the pointer 
>>> variables involved to NULL or 0.
>>>
>>> Order is largely irrelevant except in the reference loop case. 
>>> Sometimes it's important to know which part of a reference loop needs 
>>> to go away first. Perhaps you need to force a bunch of objects to go 
>>> away before a window is destroyed (for example).
>>>
>>> That's the beauty of reference counted systems: order doesn't matter 
>>> as much as balance does...
>>>
>>> If you can't figure out where there's a missing Delete or UnRegister 
>>> call, look for loops in pointer members (does your pipeline have a 
>>> feedback loop??) It sometimes helps to draw a diagram of the 
>>> pipeline. Or you could try simplifying it bit by bit and see when the 
>>> leak goes away... Then start adding things back in until the leak 
>>> comes back. That should point out where to look in the code...
>>>
>>>
>>> Hope this helps,
>>> David
>>>
>>>
>>> Dominik Szczerba wrote:
>>>
>>>> Hi,
>>>>
>>>> I have a quite complex pipeline with a few actors and filters. When 
>>>> I clean up at the end I always get a non-zero reference count 
>>>> somewhere (using C++). How do I robustly know in which order I 
>>>> should Delete my components?
>>>>
>>>> PS. this is particularly annoying in combination matlab-vtk, as 
>>>> matlab dies on any of such errors.
>>>>
>>>> regards,
>>>> Dominik
>>>> _______________________________________________
>>>> This is the private VTK discussion list. Please keep messages 
>>>> on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>>>> Follow this link to subscribe/unsubscribe:
>>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>>
>>

-- 
Dominik Szczerba, Ph.D.
Computer Vision Lab CH-8092 Zurich
http://www.vision.ee.ethz.ch/~domi



More information about the vtkusers mailing list