[vtkusers] Does ->Delete() free all resources?

Charl P. Botha cpbotha at gmail.com
Tue Nov 23 03:42:20 EST 2004


On Mon, 22 Nov 2004 11:14:33 -0700, Andrew Wilford <andrew at artwork.com> wrote:
> My question is about the use of ->Delete() and what resources it frees up.

->Delete() does not necessarily free resources up, it only removes a
reference.  Only when  the object reference count reaches 0, the
object is destroyed.  For example (untested code, just for
demonstration purposes):

====
ren = vtkRenderer::New();
ss = vtkSphereSource::New();
sm = vtkPolyDataMapper::New();
sa = vtkActor::New();

sm->SetInput(ss->GetOutput());
sa->SetMapper(sm);
ren->AddActor(sa);

ss->Delete();
sm->Delete();
sa->Delete();
====

No object will be cleaned up, because there are a chain of references
being held... ren has a reference to the actor, the actor has a
reference to the mapper and so forth.  Only when ->Delete() is called
on the renderer will all objects be cleaned up (in this case).

In short: only when your ::New() and ->Delete() calls are symmetric in
their number and in the objects that they are called on will things be
cleaned up.  Obviously, you can disconnect objects in order to
Delete() them but keep the rest of the pipeline hanging around.

HTH,
Charl

-- 
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/



More information about the vtkusers mailing list