[vtkusers] What will happen if I don't delete vtk objects on exit?

David Doria daviddoria+vtk at gmail.com
Fri Dec 18 07:37:12 EST 2009


On Fri, Dec 18, 2009 at 6:24 AM, hampycalc <
i.am.tom.hampshire at googlemail.com> wrote:

>
> The operating system will free all application memory when the thread is
> terminated, so all memory assigned to your vtk objects will also be freed.
> If you don't delete your objects, you will only get memory leaks while the
> application is running. If you are just running a short script you *could*
> not bother deleting your objects.... although it is good practice to do so.
>
> Regards
>
>
>
Current practice is to use smart pointers and you don't have to worry about
deleting the objects.

Simply change

vtkClass* class = vtkClass::New();

to

#include <vtkSmartPointer.h>
vtkSmartPointer<vtkClass> class = vtkSmartPointer<vtkClass>::New();

There is a short tutorial here: http://www.vtk.org/Wiki/Smart_Pointers

Thanks,

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


More information about the vtkusers mailing list