[vtkusers] Freeing up memory

Mike Jackson imikejackson at gmail.com
Sat Aug 4 18:58:44 EDT 2007


> vtkRendererCollection* rendererCollection = renderWin->GetRenderers();

You are getting a POINTER to an object that you DO NOT own. You do  
not have to call redererCollectio::Delete().

If you use the following:

vtkRendererCollection* rendererCollection = vtkRendererCollection::New 
();

then you have to call ::Delete()  on the object. In other words, if  
you did _Create_ the object then you do NOT need to free the memory.

If you DID create the object then you are responsible for freeing the  
memory.

Lastly, if you use the vtkSmartPointer class then you will not need  
to worry about any of the above when creating objects as vtk will "do  
the right thing" because the objects are reference counted.

vtkSmartPointer<vtkPoints> nodes = vtkSmartPointer<vtkPoints>::New();
when the context that this was created is exited (method or block)  
then the smartpointer destructor is called and the object will be  
deleted if the ref count is 0. If you passed the object as an  
argument to another method, and the method needs to keep the object  
around longer, then that method will increment the ref count  
( vtkObject.register() ).

HTH
-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services


On Aug 4, 2007, at 4:05 PM, rashed karim wrote:

> Hi VTK users,
>
> Inside a function I do this:
> vtkRendererCollection* rendererCollection = renderWin->GetRenderers();
>
> Where I am basically getting the renderers associated with a  
> rendering window. Further down in the code I extract the renderer  
> from the collection and delete any existing actors in the renderer  
> and replace it with a new actor.
>
> When exiting the function, I start freeing up the memory by  
> invoking on Delete( ) on the renderer, actor, etc. But here is  
> where it gets all wierd - when I delete the rendererCollection  
> object, I can no longer interact with my actor. Does anyone know why?
>
> Thanks
> Rashed Karim.
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070804/fc270f31/attachment.htm>


More information about the vtkusers mailing list