[vtkusers] Delete actor and release memory

Xiaofeng Z xf10036 at hotmail.com
Wed Jul 6 21:41:17 EDT 2011


VTK deletes an object when the reference count of the object becomes zero.  At this point, the OS is free to reclaim the memory and write to the memory chunk once occupied by the object.  Your debug, however, does not know this and try to deciper the chunk of memory pointed by the pointer variable.  Hence the meaningless values.  The heap profiler probably avoids immediate reuse of the memory, hence leaving the reference count value etc. intact.

Xiaofeng Zhao


 Date: Wed, 6 Jul 2011 17:34:51 -0400
Subject: Re: [vtkusers] Delete actor and release memory
From: nicolas.lists at gmail.com
To: drescherjm at gmail.com
CC: xf10036 at hotmail.com; vtkusers at public.kitware.com



On Wed, Jul 6, 2011 at 4:06 PM, John Drescher <drescherjm at gmail.com> wrote:

On Wed, Jul 6, 2011 at 3:56 PM, Nicolas Rannou <nicolas.lists at gmail.com> wrote:

>

>

> On Wed, Jul 6, 2011 at 3:43 PM, John Drescher <drescherjm at gmail.com> wrote:

>>

>> On Wed, Jul 6, 2011 at 10:35 AM, Xiaofeng Z <xf10036 at hotmail.com> wrote:

>> > That's interesting, and quite unintuitive! maybe someone with better

>> > understanding of VTK's inner work can offer an explanation!

>> >

>>

>> To me this looks like garbage being left over after the object was

>> deleted. You need to look at the reference counts before the delete

>> not after.

>>

>> John

>

> How could I avoid garbage being left over?



What I mean is after the Delete if the object was really deleted the

reference counts could be not trusted because the memory holding the

reference counts would be freed. I would trace through the code to see

what exactly is happening.



John



Ok I see what you mean now.
I'll try to debug it step by step and see what is happening...
I used to rely on the system monitor to get a gross approximation of the memory usage but it looks like it is quite not reliable.

I debugged my program with massif (http://valgrind.org/docs/manual/ms-manual.html) and the memory usage looks fine.
(the memory usage decreases significantly after deleting actors, mappers and polydatas)
A surprising thing is that, if I run my program with this heap profiler tool, the ref counts of the polydatas, mappers and actors are "accurate" (==0) after deleting the objects. The same program without the heap profiler returns weird ref counts after deleting the objects.

I'm wondering if the memory usage looks fine into massif because the ref counts are corrects (==0) or if the system monitor is just wrong and the ref counts don't really matter.In other words, if I get ref counts == 0 in my program (without heap profiler), would I be able to see the memory usage decrease in the system monitor?

Thanks 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110706/45f215a1/attachment.htm>


More information about the vtkusers mailing list