[vtkusers] Memory management issues: how to track memory usage?

David Lonie david.lonie at kitware.com
Thu Aug 11 08:40:11 EDT 2016

On Wed, Aug 10, 2016 at 5:49 PM, BBerco <bebe0705 at colorado.edu> wrote:
> Hum, I've noticed a first oddity illustrated by the two variables below (both
> being instances of
> vtkSmartPointer<vtkPolyData>):
> (...)
> this -> selected_cells_polydata -> Delete();
> this -> unselected_cells_polydata -> Delete();
> std::cout << this -> selected_cells_polydata-> GetActualMemorySize() <<
> std::endl;
> std::cout << this -> unselected_cells_polydata -> GetActualMemorySize() <<
> std::endl;
> (...)
> The two calls to GetActualMemorySize() return non-zero memory usage, after
> Delete() has been called. What am I missing here?

If the objects have been freed, the results of calling their methods
are unpredictable -- I'm surprised this didn't segfault off the bat.
It's likely returning stale/garbage memory.

Alternatively, remember that Delete() doesn't always free the object
-- it just decrements the reference count and will only free memory
once the reference count reaches 0. So if there's another existing
reference (for instance, from the vtkSmartPointer), the object will
still exist and hold memory. You can call GetReferenceCount() on them
to see how many references are currently held.


More information about the vtkusers mailing list