Main Page | Directories | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

vtkGarbageCollector Class Reference

#include <vtkGarbageCollector.h>

Inheritance diagram for vtkGarbageCollector:

Inheritance graph
[legend]
Collaboration diagram for vtkGarbageCollector:

Collaboration graph
[legend]
List of all members.

Detailed Description

Detect and break reference loops.

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.

Created by:
  • King, Brad
CVS contributions (if > 5%):
  • King, Brad (96%)
CVS logs (CVSweb):
  • .cxx (/Common/vtkGarbageCollector.cxx)
  • .h (/Common/vtkGarbageCollector.h)

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)
vtkGarbageCollectorSafeDownCast (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 *)


Member Typedef Documentation

typedef vtkObject vtkGarbageCollector::Superclass
 

Reimplemented from vtkObject.

Definition at line 98 of file vtkGarbageCollector.h.


Constructor & Destructor Documentation

vtkGarbageCollector::vtkGarbageCollector vtkGarbageCollectorInternals *   )  [protected]
 

vtkGarbageCollector::~vtkGarbageCollector  )  [protected]
 


Member Function Documentation

virtual const char* vtkGarbageCollector::GetClassName  )  [virtual]
 

Reimplemented from vtkObject.

int vtkGarbageCollector::IsTypeOf const char *  type  )  [static]
 

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.

virtual int vtkGarbageCollector::IsA const char *  type  )  [virtual]
 

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.

vtkGarbageCollector* vtkGarbageCollector::SafeDownCast vtkObject o  )  [static]
 

Reimplemented from vtkObject.

void vtkGarbageCollector::PrintSelf ostream &  os,
vtkIndent  indent
[virtual]
 

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.

void vtkGarbageCollector::Check vtkObjectBase root  )  [static]
 

Called by the UnRegister method of an object that supports garbage collection to check for a connected component starting at itself.

void vtkGarbageCollector::ReportReference vtkObjectBase ,
const char * 
 

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.

void vtkGarbageCollector::SetGlobalDebugFlag int  flag  )  [static]
 

Set/Get global garbage collection debugging flag. When set to 1, all garbage collection checks will produce debugging information.

int vtkGarbageCollector::GetGlobalDebugFlag  )  [static]
 

Set/Get global garbage collection debugging flag. When set to 1, all garbage collection checks will produce debugging information.

virtual void vtkGarbageCollector::Register vtkObjectBase  )  [protected, virtual]
 

Prevent normal vtkObject reference counting behavior.

Reimplemented from vtkObject.

virtual void vtkGarbageCollector::UnRegister vtkObjectBase  )  [protected, virtual]
 

Prevent normal vtkObject reference counting behavior.

Reimplemented from vtkObject.

void vtkGarbageCollector::ForwardReportReferences vtkObjectBase  )  [protected]
 

void vtkGarbageCollector::ForwardRemoveReferences vtkObjectBase  )  [static, protected]
 

void vtkGarbageCollector::ForwardGarbageCollectionStarting vtkObjectBase  )  [static, protected]
 

void vtkGarbageCollector::ForwardGarbageCollectionFinishing vtkObjectBase  )  [static, protected]
 

void vtkGarbageCollector::CheckReferenceLoops vtkObjectBase root  )  [protected]
 


The documentation for this class was generated from the following file: