VTK  9.3.0
vtkDebugLeaks.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
40#ifndef vtkDebugLeaks_h
41#define vtkDebugLeaks_h
42
43#include "vtkCommonCoreModule.h" // For export macro
44#include "vtkObject.h"
45
46#include "vtkDebug.h" // Needed for VTK_DEBUG_LEAKS macro setting.
47#include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
48
49#include <mutex> // for std::mutex
50
51VTK_ABI_NAMESPACE_BEGIN
52class vtkDebugLeaksHashTable;
53class vtkDebugLeaksTraceManager;
55
56class VTKCOMMONCORE_EXPORT vtkDebugLeaks : public vtkObject
57{
58public:
59 static vtkDebugLeaks* New();
60 vtkTypeMacro(vtkDebugLeaks, vtkObject);
61 void PrintSelf(ostream& os, vtkIndent indent) override;
62
66 static void ConstructClass(vtkObjectBase* object);
67
71 static void ConstructClass(const char* className);
72
76 static void DestructClass(vtkObjectBase* object);
77
81 static void DestructClass(const char* className);
82
87 static int PrintCurrentLeaks();
88
90
94 static int GetExitError();
95 static void SetExitError(int);
97
100
101protected:
102 vtkDebugLeaks() = default;
103 ~vtkDebugLeaks() override = default;
104
105 static int DisplayMessageBox(const char*);
106
107 static void ClassInitialize();
108 static void ClassFinalize();
109
110 static void ConstructingObject(vtkObjectBase* object);
111 static void DestructingObject(vtkObjectBase* object);
112
114 friend class vtkObjectBase;
115
116private:
117 static vtkDebugLeaksHashTable* MemoryTable;
118 static vtkDebugLeaksTraceManager* TraceManager;
119 static std::mutex* CriticalSection;
120 static vtkDebugLeaksObserver* Observer;
121 static int ExitError;
122
123 vtkDebugLeaks(const vtkDebugLeaks&) = delete;
124 void operator=(const vtkDebugLeaks&) = delete;
125};
126
127// This class defines callbacks for debugging tools. The callbacks are not for general use.
128// The objects passed as arguments to the callbacks are in partially constructed or destructed
129// state and accessing them may cause undefined behavior.
130class VTKCOMMONCORE_EXPORT vtkDebugLeaksObserver
131{
132public:
133 virtual ~vtkDebugLeaksObserver() = default;
136};
137
138VTK_ABI_NAMESPACE_END
139#endif // vtkDebugLeaks_h
Manages the vtkDebugLeaks singleton.
virtual ~vtkDebugLeaksObserver()=default
virtual void DestructingObject(vtkObjectBase *)=0
virtual void ConstructingObject(vtkObjectBase *)=0
identify memory leaks at program termination vtkDebugLeaks is used to report memory leaks at the exit...
static void ConstructClass(vtkObjectBase *object)
Call this when creating a class.
static void SetExitError(int)
Get/Set flag for exiting with an error when leaks are present.
static void ConstructingObject(vtkObjectBase *object)
vtkDebugLeaks()=default
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
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.
~vtkDebugLeaks() override=default
static vtkDebugLeaks * New()
static vtkDebugLeaksObserver * GetDebugLeaksObserver()
static void ClassFinalize()
static void DestructClass(vtkObjectBase *object)
Call this when deleting a class.
a simple class to control print indentation
Definition vtkIndent.h:29
abstract base class for most VTK objects
friend class vtkDebugLeaks
abstract base class for most VTK objects
Definition vtkObject.h:49