VTK
vtkGarbageCollector.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkGarbageCollector.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=========================================================================*/
82#ifndef vtkGarbageCollector_h
83#define vtkGarbageCollector_h
84
85#include "vtkCommonCoreModule.h" // For export macro
86#include "vtkObject.h"
87#include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
88
89// This function is a friend of the collector so that it can call the
90// internal report method.
91void VTKCOMMONCORE_EXPORT
93 vtkObjectBase*, void*,
94 const char*);
95
96// This allows vtkObjectBase to get at the methods it needs.
97class vtkObjectBaseToGarbageCollectorFriendship;
98
99class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
100{
101public:
103 void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
105
118 static void Collect();
119
131 static void Collect(vtkObjectBase* root);
132
134
143
145
149 static void SetGlobalDebugFlag(bool flag);
150 static bool GetGlobalDebugFlag();
152
153protected:
155 ~vtkGarbageCollector() VTK_OVERRIDE;
156
157private:
158
169 static int GiveReference(vtkObjectBase* obj);
170
179 static int TakeReference(vtkObjectBase* obj);
180
181 // Singleton management functions.
182 static void ClassInitialize();
183 static void ClassFinalize();
184
186 friend class vtkObjectBaseToGarbageCollectorFriendship;
187
188 // Internal report callback and friend function that calls it.
189 virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
190 friend void VTKCOMMONCORE_EXPORT
192 vtkObjectBase*, void*,
193 const char*);
194
195private:
196 vtkGarbageCollector(const vtkGarbageCollector&) VTK_DELETE_FUNCTION;
197 void operator=(const vtkGarbageCollector&) VTK_DELETE_FUNCTION;
198};
199
201
205void VTKCOMMONCORE_EXPORT
208 const char* desc);
209
213template <class T>
215 const char* desc)
216{
217 vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
218}
219
220#endif
221// VTK-HeaderTest-Exclude: vtkGarbageCollector.h
Manages the vtkGarbageCollector singleton.
Detect and break reference loops.
static vtkGarbageCollector * New()
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static void DeferredCollectionPop()
static void DeferredCollectionPush()
Push/Pop whether to do deferred collection.
static void Collect(vtkObjectBase *root)
Collect immediately using the given object as the root for a reference graph walk.
static void SetGlobalDebugFlag(bool flag)
Set/Get global garbage collection debugging flag.
~vtkGarbageCollector() override
static void Collect()
Collect immediately using any objects whose collection was previously deferred as a root for the refe...
static bool GetGlobalDebugFlag()
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObjectBase.h:66
abstract base class for most VTK objects
Definition: vtkObject.h:60
Non-templated superclass for vtkSmartPointer.
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(vtkGarbageCollector *collector, vtkSmartPointerBase &ptr, const char *desc)
Function to report a reference held by a smart pointer to a collector.
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)