Commit 75ca1bd2 authored by Pat Marion's avatar Pat Marion
Browse files

Add new api to vtkDebugLeaks to track vtk object lifetime

Change-Id: I5c45fbc337fc7c1fccdbef4c831624862f7cbfb9
parent c345717a
......@@ -305,6 +305,36 @@ void vtkDebugLeaks::DestructClass(const char*)
}
#endif
//----------------------------------------------------------------------------
void vtkDebugLeaks::SetDebugLeaksObserver(vtkDebugLeaksObserver* observer)
{
vtkDebugLeaks::Observer = observer;
}
//----------------------------------------------------------------------------
vtkDebugLeaksObserver* vtkDebugLeaks::GetDebugLeaksObserver()
{
return vtkDebugLeaks::Observer;
}
//----------------------------------------------------------------------------
void vtkDebugLeaks::ConstructingObject(vtkObjectBase* object)
{
if (vtkDebugLeaks::Observer)
{
vtkDebugLeaks::Observer->ConstructingObject(object);
}
}
//----------------------------------------------------------------------------
void vtkDebugLeaks::DestructingObject(vtkObjectBase* object)
{
if (vtkDebugLeaks::Observer)
{
vtkDebugLeaks::Observer->DestructingObject(object);
}
}
//----------------------------------------------------------------------------
int vtkDebugLeaks::PrintCurrentLeaks()
{
......@@ -413,10 +443,12 @@ void vtkDebugLeaks::ClassInitialize()
// Default to error when leaks occur while running tests.
vtkDebugLeaks::ExitError = 1;
vtkDebugLeaks::Observer = 0;
#else
vtkDebugLeaks::MemoryTable = 0;
vtkDebugLeaks::CriticalSection = 0;
vtkDebugLeaks::ExitError = 0;
vtkDebugLeaks::Observer = 0;
#endif
}
......@@ -458,3 +490,5 @@ vtkSimpleCriticalSection* vtkDebugLeaks::CriticalSection;
// Purposely not initialized. ClassInitialize will handle it.
int vtkDebugLeaks::ExitError;
vtkDebugLeaksObserver* vtkDebugLeaks::Observer;
......@@ -33,6 +33,7 @@
class vtkDebugLeaksHashTable;
class vtkSimpleCriticalSection;
class vtkDebugLeaksObserver;
class VTK_COMMON_EXPORT vtkDebugLeaks : public vtkObject
{
......@@ -64,6 +65,10 @@ public:
// Default is on when VTK_DEBUG_LEAKS is on and off otherwise.
static int GetExitError();
static void SetExitError(int);
//BTX
static void SetDebugLeaksObserver(vtkDebugLeaksObserver* observer);
static vtkDebugLeaksObserver* GetDebugLeaksObserver();
//ETX
protected:
vtkDebugLeaks(){};
......@@ -74,17 +79,34 @@ protected:
static void ClassInitialize();
static void ClassFinalize();
static void ConstructingObject(vtkObjectBase* object);
static void DestructingObject(vtkObjectBase* object);
//BTX
friend class vtkDebugLeaksManager;
friend class vtkObjectBase;
//ETX
private:
static vtkDebugLeaksHashTable* MemoryTable;
static vtkSimpleCriticalSection* CriticalSection;
static vtkDebugLeaksObserver* Observer;
static int ExitError;
vtkDebugLeaks(const vtkDebugLeaks&); // Not implemented.
void operator=(const vtkDebugLeaks&); // Not implemented.
};
//BTX
// This class defines callbacks for debugging tools. The callbacks are not for general use.
// The objects passed as arguments to the callbacks are in partially constructed or destructed
// state and accessing them may cause undefined behavior.
class VTK_COMMON_EXPORT vtkDebugLeaksObserver {
public:
virtual ~vtkDebugLeaksObserver() {};
virtual void ConstructingObject(vtkObjectBase*) = 0;
virtual void DestructingObject(vtkObjectBase*) = 0;
};
//ETX
#endif // __vtkDebugLeaks_h
......@@ -75,10 +75,17 @@ vtkObjectBase::vtkObjectBase()
{
this->ReferenceCount = 1;
this->WeakPointers = 0;
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructingObject(this);
#endif
}
vtkObjectBase::~vtkObjectBase()
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::DestructingObject(this);
#endif
// warn user if reference counting is on and the object is being referenced
// by another object
if ( this->ReferenceCount > 0)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment