[vtkusers] Dispose to vtk objects

David Cole dlrdave at aol.com
Fri Jun 14 13:02:22 EDT 2013


> So it's better to dispose the rendering sequence manually on window close?
> And not to count on the garbage collector?
> Are there objects that can cause a memory leak somehow?
> For example, if I create an actor and then its reference gets null without
> disposing it, is it a memory leak?
> (The code written in activiz)



You shouldn’t get any memory leaks. Either your manual Dispose, or the garbage collector’s eventual Dispose should properly delete things for you.


Most of the problems come into play when the garbage collector decides to Dispose of something while it’s still connected to something else on the C++ side. Then, later, when that thing it’s connected to is being deleted, if it tries to call something on the already earlier deleted object, it can crash trying to access memory that’s already been freed.


It doesn’t usually happen because VTK has ref-counted objects and they’ll mostly be kept alive long enough to avoid this scenario.


The general rule of thumb, when using ActiViz .NET, should be: if you allocate an object explicitly with C# new, and then add it to some network of connected objects.... then later you should remove it from that network, and Dispose of the object, and set the C# variable to null.


For the most part, you should be able to do things through VTK methods, and it should all happen automatically.


I would have to take a look at a chunk of specific code to tell you whether the Dispose calls are really necessary or not. In general, you don’t need to call Dispose yourself. Try the code without Dispose calls, and see what happens.



Hope this helps,

D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130614/95f4effe/attachment.htm>


More information about the vtkusers mailing list