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