VTK  9.2.6
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 =========================================================================*/
52 #ifndef vtkDebugLeaks_h
53 #define vtkDebugLeaks_h
54 
55 #include "vtkCommonCoreModule.h" // For export macro
56 #include "vtkObject.h"
57 
58 #include "vtkDebug.h" // Needed for VTK_DEBUG_LEAKS macro setting.
59 #include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
60 
61 #include <mutex> // for std::mutex
62 
63 class vtkDebugLeaksHashTable;
64 class vtkDebugLeaksTraceManager;
66 
67 class VTKCOMMONCORE_EXPORT vtkDebugLeaks : public vtkObject
68 {
69 public:
70  static vtkDebugLeaks* New();
71  vtkTypeMacro(vtkDebugLeaks, vtkObject);
72  void PrintSelf(ostream& os, vtkIndent indent) override;
73 
77  static void ConstructClass(vtkObjectBase* object);
78 
82  static void ConstructClass(const char* className);
83 
87  static void DestructClass(vtkObjectBase* object);
88 
92  static void DestructClass(const char* className);
93 
98  static int PrintCurrentLeaks();
99 
101 
105  static int GetExitError();
106  static void SetExitError(int);
108 
109  static void SetDebugLeaksObserver(vtkDebugLeaksObserver* observer);
110  static vtkDebugLeaksObserver* GetDebugLeaksObserver();
111 
112 protected:
113  vtkDebugLeaks() = default;
114  ~vtkDebugLeaks() override = default;
115 
116  static int DisplayMessageBox(const char*);
117 
118  static void ClassInitialize();
119  static void ClassFinalize();
120 
121  static void ConstructingObject(vtkObjectBase* object);
122  static void DestructingObject(vtkObjectBase* object);
123 
124  friend class vtkDebugLeaksManager;
125  friend class vtkObjectBase;
126 
127 private:
128  static vtkDebugLeaksHashTable* MemoryTable;
129  static vtkDebugLeaksTraceManager* TraceManager;
130  static std::mutex* CriticalSection;
131  static vtkDebugLeaksObserver* Observer;
132  static int ExitError;
133 
134  vtkDebugLeaks(const vtkDebugLeaks&) = delete;
135  void operator=(const vtkDebugLeaks&) = delete;
136 };
137 
138 // This class defines callbacks for debugging tools. The callbacks are not for general use.
139 // The objects passed as arguments to the callbacks are in partially constructed or destructed
140 // state and accessing them may cause undefined behavior.
141 class VTKCOMMONCORE_EXPORT vtkDebugLeaksObserver
142 {
143 public:
144  virtual ~vtkDebugLeaksObserver() = default;
145  virtual void ConstructingObject(vtkObjectBase*) = 0;
146  virtual void DestructingObject(vtkObjectBase*) = 0;
147 };
148 
149 #endif // vtkDebugLeaks_h
abstract base class for most VTK objects
Definition: vtkObject.h:62
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition: vtkIndent.h:39
friend class vtkDebugLeaks
abstract base class for most VTK objects
Definition: vtkObjectBase.h:73
identify memory leaks at program termination vtkDebugLeaks is used to report memory leaks at the exit...
Definition: vtkDebugLeaks.h:67
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.