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 
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
Manages the vtkDebugLeaks singleton.
virtual void DestructingObject(vtkObjectBase *)=0
virtual ~vtkDebugLeaksObserver()
virtual void ConstructingObject(vtkObjectBase *)=0
identify memory leaks at program termination vtkDebugLeaks is used to report memory leaks at the exit...
Definition: vtkDebugLeaks.h:64
~vtkDebugLeaks() override
static vtkDebugLeaks * New()
static void ConstructClass(vtkObjectBase *object)
Call this when creating a class.
static void SetExitError(int)
static void ConstructingObject(vtkObjectBase *object)
static void ClassInitialize()
static void SetDebugLeaksObserver(vtkDebugLeaksObserver *observer)
static void DestructClass(const char *className)
Call this when deleting vtkCommand or a subclass.
static void ConstructClass(const char *className)
Call this when creating a vtkCommand or subclasses.
static int PrintCurrentLeaks()
Print all the values in the table.
static int DisplayMessageBox(const char *)
static void DestructingObject(vtkObjectBase *object)
static int GetExitError()
Get/Set flag for exiting with an error when leaks are present.
static vtkDebugLeaksObserver * GetDebugLeaksObserver()
static void ClassFinalize()
static void DestructClass(vtkObjectBase *object)
Call this when deleting a class.
abstract base class for most VTK objects
Definition: vtkObjectBase.h:64
void operator=(const vtkObjectBase &)
abstract base class for most VTK objects
Definition: vtkObject.h:63
Critical section locking class.