[vtkusers] Destroying objects from Python

bryan cole bryan.cole at teraview.co.uk
Wed Oct 2 05:02:32 EDT 2002


Thanks, this clarifies things somewhat. How about the following:

Take the case where I want to replace a section of the visualisation
pipline.

Source->Filter1->Filter2->Mapper

If I disconnect the pair of filters (for example) by resetting the
inputs and outputs of the mapper and source respectively, to replace
them with some other filters, how do I destroy the redundant Filter1 and
Filter2?

According to my understanding, using 
del Filter1
del Filter2
will simply remove the label for each filter (hence decreasing their
ref-counts by one). However Since the filters are still connected to
each other, they still have references >=1 so are not destroyed. Thus I
must break the connection between the filters before they are destroyed.
How do I do this? Can I set their inputs to NULL?

Bryan

> 
> So here is an example demonstrating how it all works:
> 
> >>> import sys
> >>> import vtk
> >>> cs = vtk.vtkConeSource()
> >>> out = cs.GetOutput()
> >>> print sys.getrefcount (out)
>  2
> >>> print out.GetReferenceCount ()
>  3
> >>> m = vtk.vtkPolyDataMapper()
> >>> m.SetInput(out)
> >>> print out.GetReferenceCount()
>  4
> >>> print sys.getrefcount (out)
>  2
> >>> o = out
> >>> sys.getrefcount (out)
> 3
> >>> print out.GetReferenceCount ()
> 4
> # Now how are objects deleted?
> >>> print cs.GetReferenceCount()
> 3
> >>> print sys.getrefcount(cs)
> 2
> # Now turn on debug to see if the object is indeed deleted.
> >>> cs.DebugOn()
> >>> del cs
> Debug: In /skratch/prabhu/vtk/cvs/VTK/Common/vtkObject.cxx, line 230
> vtkConeSource (0x819e468): UnRegistered by NULL, ReferenceCount = 2
> 
> Debug: In /skratch/prabhu/vtk/cvs/VTK/Common/vtkObject.cxx, line 230
> vtkConeSource (0x819e468): UnRegistered by NULL, ReferenceCount = 1
> >>> 
> # this object is not deleted because out still holds a reference
> # internally.
> >>> del out
> # still nothing happens because GetOutput() is still held by the
> # mapper.
> >>> del m
> Debug: In /skratch/prabhu/vtk/cvs/VTK/Common/vtkObject.cxx, line 225
> vtkConeSource (0x819d1d0): UnRegistered by vtkPolyData (0x8136640), ReferenceCount = 0
> 
> Debug: In /skratch/prabhu/vtk/cvs/VTK/Common/vtkObject.cxx, line 126
> vtkObject (0x819d1d0): Destructing!
> 
> I think this explains everything. :)
> 
> prabhu
-- 
Bryan Cole
Teraview Ltd., 302-304 Cambridge Science Park, Milton Road, Cambridge
CB4 0WG, United Kingdom.
tel: +44 (1223) 435380 / 435386 (direct-dial) fax: +44 (1223) 435382




More information about the vtkusers mailing list