#include <vtkGarbageCollector.h>
Inheritance diagram for vtkGarbageCollector:
vtkGarbageCollector is used by VTK classes that may be involved in reference counting loops (such as Source <-> Output). It detects connected components of the reference graph that have been disconnected from the main graph and deletes them. Objects that use it call CheckReferenceLoops from their UnRegister method and pass themselves as the root for a search. The garbage collector then uses the ReportReferences method to search the reference graph and construct a net reference count for the object's connected component. If the net reference count is zero, RemoveReferences is called on all objects to break references and the entire set of objects is then deleted.
To enable garbage collection for a class, add these members:
public: virtual void UnRegister(vtkObjectBase* o) { int check = (this->GetReferenceCount() > 1); this->Superclass::UnRegister(o); if(check && !this->GarbageCollecting) { vtkGarbageCollector::CheckReferenceLoops(this); } }
protected: Initialize to zero in the constructor. int GarbageCollecting;
virtual void ReportReferences(vtkGarbageCollector* collector) { Report references held by this object that may be in a loop. this->Superclass::ReportReferences(collector); collector->ReportReference(this->OtherObject); }
virtual void RemoveReferences() { Remove references to objects reported in ReportReferences. if(this->OtherObject) { this->OtherObject->UnRegister(this); this->OtherObject = 0; } this->Superclass::RemoveReferences(); }
virtual void GarbageCollectionStarting() { this->GarbageCollecting = 1; this->Superclass::GarbageCollectionStarting(); }
The implementations should be in the .cxx file in practice.
If subclassing from a class that already supports garbage collection, one need only provide the ReportReferences and RemoveReferences methods.
Definition at line 95 of file vtkGarbageCollector.h.
Public Types | |
typedef vtkObject | Superclass |
Public Member Functions | |
virtual const char * | GetClassName () |
virtual int | IsA (const char *type) |
void | PrintSelf (ostream &os, vtkIndent indent) |
void | ReportReference (vtkObjectBase *, const char *) |
Static Public Member Functions | |
int | IsTypeOf (const char *type) |
vtkGarbageCollector * | SafeDownCast (vtkObject *o) |
void | Check (vtkObjectBase *root) |
void | SetGlobalDebugFlag (int flag) |
int | GetGlobalDebugFlag () |
Protected Member Functions | |
vtkGarbageCollector (vtkGarbageCollectorInternals *) | |
~vtkGarbageCollector () | |
virtual void | Register (vtkObjectBase *) |
virtual void | UnRegister (vtkObjectBase *) |
void | ForwardReportReferences (vtkObjectBase *) |
void | CheckReferenceLoops (vtkObjectBase *root) |
Static Protected Member Functions | |
void | ForwardRemoveReferences (vtkObjectBase *) |
void | ForwardGarbageCollectionStarting (vtkObjectBase *) |
void | ForwardGarbageCollectionFinishing (vtkObjectBase *) |
|
Reimplemented from vtkObject. Definition at line 98 of file vtkGarbageCollector.h. |
|
|
|
|
|
Reimplemented from vtkObject. |
|
Return 1 if this class type is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeRevisionMacro found in vtkSetGet.h. Reimplemented from vtkObject. |
|
Return 1 if this class is the same type of (or a subclass of) the named class. Returns 0 otherwise. This method works in combination with vtkTypeRevisionMacro found in vtkSetGet.h. Reimplemented from vtkObject. |
|
Reimplemented from vtkObject. |
|
Methods invoked by print to print information about the object including superclasses. Typically not called by the user (use Print() instead) but used in the hierarchical print process to combine the output of several classes. Reimplemented from vtkObject. |
|
Called by the UnRegister method of an object that supports garbage collection to check for a connected component starting at itself. |
|
Called by the ReportReferences method of objects in a reference graph to report an outgoing connection. The first argument should point to the reported reference is made. The second argument should be a brief description of how the reference is made for use in debugging reference loops. |
|
Set/Get global garbage collection debugging flag. When set to 1, all garbage collection checks will produce debugging information. |
|
Set/Get global garbage collection debugging flag. When set to 1, all garbage collection checks will produce debugging information. |
|
Prevent normal vtkObject reference counting behavior. Reimplemented from vtkObject. |
|
Prevent normal vtkObject reference counting behavior. Reimplemented from vtkObject. |
|
|
|
|
|
|
|
|
|
|