[vtkusers] [FORGED] Re: Freeing actor memory

Gib Bogle g.bogle at auckland.ac.nz
Sat Dec 1 09:48:42 EST 2018


Thanks Elvis.  Good to know that this is a valid approach.  What about the order of destroying the smart pointers.  Should that be the reverse of the order in which they are created?

Cheers, Gib
________________________________________
From: Elvis Stansvik <elvis.stansvik at orexplore.com>
Sent: Sunday, 2 December 2018 3:27 a.m.
To: Gib Bogle
Cc: VTK Users
Subject: [FORGED] Re: [vtkusers] Freeing actor memory

Den fre 30 nov. 2018 kl 19:12 skrev Gib Bogle <g.bogle at auckland.ac.nz>:
>
> I am sequentially rendering a scene composed of an increasing number of actors, each of which is a clipped and capped cone (to be precise, each member of the scene is made up of two actors – the clipped cone and the cap).    I am not sure about the right way to remove the actors and free the associated memory when the time comes.  The list of things created with New() for each composite actor is quite long (the code is based on the CapClip example.):
>
>
>
> coneSource = vtkSmartPointer<vtkConeSource>::New();
>
> plane = vtkSmartPointer<vtkPlane>::New();
>
> clipMapper = vtkSmartPointer<vtkDataSetMapper>::New();
>
> clipActor = vtkSmartPointer<vtkActor>::New();
>
> boundaryEdges = vtkSmartPointer<vtkFeatureEdges>::New();
>
> boundaryStrips = vtkSmartPointer<vtkStripper>::New();
>
> boundaryPoly = vtkSmartPointer<vtkPolyData>::New();
>
> boundaryMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
>
> boundaryActor = vtkSmartPointer<vtkActor>::New();
>
>
>
> My proposed approach is to use a struct to hold all the vtkSmartPointers, creating a new ACTOR_STRUCT (stored in an array or list) every time a composite actor is created:
>
>
>
> struct actor_struct {
>
>        vtkSmartPointer<vtkConeSource> coneSource;
>
>        vtkSmartPointer<vtkPlane> plane;
>
>        vtkSmartPointer<vtkClipPolyData> clipper;
>
>        vtkSmartPointer<vtkDataSetMapper> clipMapper;
>
>        vtkSmartPointer<vtkActor> clipActor;
>
>        vtkSmartPointer<vtkFeatureEdges> boundaryEdges;
>
>        vtkSmartPointer<vtkStripper> boundaryStrips;
>
>        vtkSmartPointer<vtkPolyData> boundaryPoly;
>
>        vtkSmartPointer<vtkPolyDataMapper> boundaryMapper;
>
>        vtkSmartPointer<vtkActor> boundaryActor;
>
> };
>
> typedef actor_struct ACTOR_STRUCT;
>
>
>
> The motivation is to be able to locate all the allocated objects when memory needs to be freed, but I suspect it is neither the conventional nor the best way.  I have two questions:

I don't know about conventional, but that's how we do it too. In
various places, we have structs or classes that hold smart pointers to
the VTK objects we need to keep alive.

>
>
>
> What is the usual way to handle this situation?
>
> If my proposed method is OK, how should all the actor memory be freed?

The objects will be freed when the smart pointer to them is destroyed
(provided no other user has increased the RefCount of the objects).

HTH,
Elvis

>
>
>
> I’d be grateful if somebody with a better understanding of VTK and C++ could advise me.
>
>
>
> Thanks
>
> Gib
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers


More information about the vtkusers mailing list