VTK  9.0.1
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 "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
56 #include "vtkToolkits.h" // Needed for VTK_DEBUG_LEAKS macro setting.
57 
58 class vtkDebugLeaksHashTable;
59 class vtkDebugLeaksTraceManager;
62 
63 class VTKCOMMONCORE_EXPORT vtkDebugLeaks : public vtkObject
64 {
65 public:
66  static vtkDebugLeaks* New();
67  vtkTypeMacro(vtkDebugLeaks, vtkObject);
68 
72  static void ConstructClass(vtkObjectBase* object);
73 
77  static void ConstructClass(const char* className);
78 
82  static void DestructClass(vtkObjectBase* object);
83 
87  static void DestructClass(const char* className);
88 
93  static int PrintCurrentLeaks();
94 
96 
100  static int GetExitError();
101  static void SetExitError(int);
103 
104  static void SetDebugLeaksObserver(vtkDebugLeaksObserver* observer);
105  static vtkDebugLeaksObserver* GetDebugLeaksObserver();
106 
107 protected:
109  ~vtkDebugLeaks() override {}
110 
111  static int DisplayMessageBox(const char*);
112 
113  static void ClassInitialize();
114  static void ClassFinalize();
115 
116  static void ConstructingObject(vtkObjectBase* object);
117  static void DestructingObject(vtkObjectBase* object);
118 
119  friend class vtkDebugLeaksManager;
120  friend class vtkObjectBase;
121 
122 private:
123  static vtkDebugLeaksHashTable* MemoryTable;
124  static vtkDebugLeaksTraceManager* TraceManager;
125  static vtkSimpleCriticalSection* CriticalSection;
126  static vtkDebugLeaksObserver* Observer;
127  static int ExitError;
128 
129  vtkDebugLeaks(const vtkDebugLeaks&) = delete;
130  void operator=(const vtkDebugLeaks&) = delete;
131 };
132 
133 // This class defines callbacks for debugging tools. The callbacks are not for general use.
134 // The objects passed as arguments to the callbacks are in partially constructed or destructed
135 // state and accessing them may cause undefined behavior.
136 class VTKCOMMONCORE_EXPORT vtkDebugLeaksObserver
137 {
138 public:
140  virtual void ConstructingObject(vtkObjectBase*) = 0;
141  virtual void DestructingObject(vtkObjectBase*) = 0;
142 };
143 
144 #endif // vtkDebugLeaks_h
145 // VTK-HeaderTest-Exclude: vtkDebugLeaks.h
abstract base class for most VTK objects
Definition: vtkObject.h:62
virtual ~vtkDebugLeaksObserver()
~vtkDebugLeaks() override
abstract base class for most VTK objects
Definition: vtkObjectBase.h:63
identify memory leaks at program termination vtkDebugLeaks is used to report memory leaks at the exit...
Definition: vtkDebugLeaks.h:63
Critical section locking class.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
void operator=(const vtkObjectBase &)
Manages the vtkDebugLeaks singleton.