VTK  9.1.0
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 "vtkDebug.h" // Needed for VTK_DEBUG_LEAKS macro setting.
56#include "vtkDebugLeaksManager.h" // Needed for proper singleton initialization
57
58#include <mutex> // for std::mutex
59
60class vtkDebugLeaksHashTable;
61class vtkDebugLeaksTraceManager;
63
64class VTKCOMMONCORE_EXPORT vtkDebugLeaks : public vtkObject
65{
66public:
67 static vtkDebugLeaks* New();
68 vtkTypeMacro(vtkDebugLeaks, vtkObject);
69 void PrintSelf(ostream& os, vtkIndent indent) override;
70
74 static void ConstructClass(vtkObjectBase* object);
75
79 static void ConstructClass(const char* className);
80
84 static void DestructClass(vtkObjectBase* object);
85
89 static void DestructClass(const char* className);
90
95 static int PrintCurrentLeaks();
96
98
102 static int GetExitError();
103 static void SetExitError(int);
105
108
109protected:
110 vtkDebugLeaks() = default;
111 ~vtkDebugLeaks() override = default;
112
113 static int DisplayMessageBox(const char*);
114
115 static void ClassInitialize();
116 static void ClassFinalize();
117
118 static void ConstructingObject(vtkObjectBase* object);
119 static void DestructingObject(vtkObjectBase* object);
120
122 friend class vtkObjectBase;
123
124private:
125 static vtkDebugLeaksHashTable* MemoryTable;
126 static vtkDebugLeaksTraceManager* TraceManager;
127 static std::mutex* CriticalSection;
128 static vtkDebugLeaksObserver* Observer;
129 static int ExitError;
130
131 vtkDebugLeaks(const vtkDebugLeaks&) = delete;
132 void operator=(const vtkDebugLeaks&) = delete;
133};
134
135// This class defines callbacks for debugging tools. The callbacks are not for general use.
136// The objects passed as arguments to the callbacks are in partially constructed or destructed
137// state and accessing them may cause undefined behavior.
138class VTKCOMMONCORE_EXPORT vtkDebugLeaksObserver
139{
140public:
141 virtual ~vtkDebugLeaksObserver() = default;
144};
145
146#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...
Definition: vtkDebugLeaks.h:65
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:113
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
void operator=(const vtkObjectBase &)
abstract base class for most VTK objects
Definition: vtkObject.h:73