VTK
vtkDebugLeaks.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkDebugLeaks.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
49 #ifndef vtkDebugLeaks_h
50 #define vtkDebugLeaks_h
51 
52 #include "vtkCommonCoreModule.h" // For export macro
53 #include "vtkObject.h"
54 
55 #include "vtkToolkits.h" // Needed for VTK_DEBUG_LEAKS macro setting.
56 #include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
57 
58 class vtkDebugLeaksHashTable;
61 
62 class VTKCOMMONCORE_EXPORT vtkDebugLeaks : public vtkObject
63 {
64 public:
65  static vtkDebugLeaks *New();
66  vtkTypeMacro(vtkDebugLeaks,vtkObject);
67 
71  static void ConstructClass(const char* classname);
72 
76  static void DestructClass(const char* classname);
77 
82  static int PrintCurrentLeaks();
83 
85 
89  static int GetExitError();
90  static void SetExitError(int);
92 
95 
96 protected:
98  ~vtkDebugLeaks() VTK_OVERRIDE{}
99 
100  static int DisplayMessageBox(const char*);
101 
102  static void ClassInitialize();
103  static void ClassFinalize();
104 
105  static void ConstructingObject(vtkObjectBase* object);
106  static void DestructingObject(vtkObjectBase* object);
107 
108  friend class vtkDebugLeaksManager;
109  friend class vtkObjectBase;
110 
111 private:
112  static vtkDebugLeaksHashTable* MemoryTable;
113  static vtkSimpleCriticalSection* CriticalSection;
114  static vtkDebugLeaksObserver* Observer;
115  static int ExitError;
116 
117  vtkDebugLeaks(const vtkDebugLeaks&) VTK_DELETE_FUNCTION;
118  void operator=(const vtkDebugLeaks&) VTK_DELETE_FUNCTION;
119 };
120 
121 // This class defines callbacks for debugging tools. The callbacks are not for general use.
122 // The objects passed as arguments to the callbacks are in partially constructed or destructed
123 // state and accessing them may cause undefined behavior.
124 class VTKCOMMONCORE_EXPORT vtkDebugLeaksObserver {
125 public:
127  virtual void ConstructingObject(vtkObjectBase*) = 0;
128  virtual void DestructingObject(vtkObjectBase*) = 0;
129 };
130 
131 #endif // vtkDebugLeaks_h
132 // VTK-HeaderTest-Exclude: vtkDebugLeaks.h
vtkObjectBase::operator=
void operator=(const vtkObjectBase &)
Definition: vtkObjectBase.h:226
vtkDebugLeaks::SetExitError
static void SetExitError(int)
vtkDebugLeaks::ClassInitialize
static void ClassInitialize()
vtkDebugLeaksObserver::DestructingObject
virtual void DestructingObject(vtkObjectBase *)=0
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkDebugLeaks::GetExitError
static int GetExitError()
Get/Set flag for exiting with an error when leaks are present.
vtkDebugLeaks::DisplayMessageBox
static int DisplayMessageBox(const char *)
vtkDebugLeaks::ConstructingObject
static void ConstructingObject(vtkObjectBase *object)
vtkDebugLeaks::ClassFinalize
static void ClassFinalize()
vtkDebugLeaks::ConstructClass
static void ConstructClass(const char *classname)
Call this when creating a class of a given name.
vtkDebugLeaks::PrintCurrentLeaks
static int PrintCurrentLeaks()
Print all the values in the table.
vtkDebugLeaksManager.h
vtkDebugLeaks::DestructClass
static void DestructClass(const char *classname)
Call this when deleting a class of a given name.
vtkDebugLeaks::GetDebugLeaksObserver
static vtkDebugLeaksObserver * GetDebugLeaksObserver()
vtkDebugLeaks::vtkDebugLeaks
vtkDebugLeaks()
Definition: vtkDebugLeaks.h:97
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:66
vtkSimpleCriticalSection
Critical section locking class.
Definition: vtkSimpleCriticalSection.h:67
vtkDebugLeaksObserver::~vtkDebugLeaksObserver
virtual ~vtkDebugLeaksObserver()
Definition: vtkDebugLeaks.h:126
vtkObject.h
vtkDebugLeaks
identify memory leaks at program termination vtkDebugLeaks is used to report memory leaks at the exit...
Definition: vtkDebugLeaks.h:63
vtkDebugLeaksManager
Manages the vtkDebugLeaks singleton.
Definition: vtkDebugLeaksManager.h:32
vtkDebugLeaksObserver::ConstructingObject
virtual void ConstructingObject(vtkObjectBase *)=0
vtkDebugLeaks::DestructingObject
static void DestructingObject(vtkObjectBase *object)
vtkDebugLeaksObserver
Definition: vtkDebugLeaks.h:124
vtkDebugLeaks::~vtkDebugLeaks
~vtkDebugLeaks() override
Definition: vtkDebugLeaks.h:98
vtkDebugLeaks::SetDebugLeaksObserver
static void SetDebugLeaksObserver(vtkDebugLeaksObserver *observer)
vtkDebugLeaks::New
static vtkDebugLeaks * New()