[vtkusers] Memory management issues: how to track memory usage?
david.lonie at kitware.com
Wed Aug 10 09:34:38 EDT 2016
On Wed, Aug 10, 2016 at 2:32 AM, Elvis Stansvik
<elvis.stansvik at orexplore.com> wrote:
> Den 9 aug. 2016 9:08 em skrev "BBerco" <bebe0705 at colorado.edu>:
>> Typically, opening a shape model and just leaving it there requires about
>> 300MB of memory. Selecting a region adds another 150MB to the memory
>> consumption. I was hoping to see the memory going back to 300MB once the
>> selection window is closed (and the corresponding actors/polydata
>> but I am left with 350MB of memory usage. So something did not get cleared
>> as expected.
This sounds like the operating system is caching some memory. When a
process releases memory, often times the OS will keep some of it
marked as in-use to speed up future allocations. There may be
OS-specific methods to disable this behavior or force cached memory to
be freed, though I'm not sure.
>> I understand that this very high level description of those RAM issues can
>> only get a very general answer at best. However, I was wondering if you
>> a debbugging method allowing one to track the memory used by a pointed
>> variable (variable pointed at by a vtkSmartPointer)?
Several vtkObject subclasses have a GetActualMemorySize() method.
These may be useful here.
> I believe there's a VTK_DEBUG_LEAKS CMake variable you can set when building
> VTK, which enables some memory tracking facilities. I'm afraid I don't know
> more than that, as I haven't used it myself, but would be interested in your
> findings as I've been meaning to try it out.
VTK_DEBUG_LEAKS keeps track of vtkObjects that have been allocated but
not freed. When enabled in CMake, it will print a list of all leaked
vtkObjects when the process exits. This can be handy for identifying
missing calls to vtkObject::Delete(). There's also a static method
vtkDebugLeaks::PrintCurrentLeaks() which will print a list of all
vtkObjects currently in memory, which may be helpful to compare
before/after the selection to determine if the problem is an actual
leak or a caching issue.
More information about the vtkusers