VTK  9.1.0
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=========================================================================*/
79#ifndef vtkGarbageCollector_h
80#define vtkGarbageCollector_h
81
82#include "vtkCommonCoreModule.h" // For export macro
83#include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
84#include "vtkObject.h"
85
86// This function is a friend of the collector so that it can call the
87// internal report method.
88void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
89 vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
90
91// This allows vtkObjectBase to get at the methods it needs.
92class vtkObjectBaseToGarbageCollectorFriendship;
93
94class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
95{
96public:
98 void PrintSelf(ostream& os, vtkIndent indent) override;
100
113 static void Collect();
114
126 static void Collect(vtkObjectBase* root);
127
129
138
140
144 static void SetGlobalDebugFlag(bool flag);
145 static bool GetGlobalDebugFlag();
147
148protected:
151
152private:
163 static int GiveReference(vtkObjectBase* obj);
164
173 static int TakeReference(vtkObjectBase* obj);
174
175 // Singleton management functions.
176 static void ClassInitialize();
177 static void ClassFinalize();
178
180 friend class vtkObjectBaseToGarbageCollectorFriendship;
181
182 // Internal report callback and friend function that calls it.
183 virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
184 friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
185 vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
186
187private:
189 void operator=(const vtkGarbageCollector&) = delete;
190};
191
193
197void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(
198 vtkGarbageCollector* collector, vtkSmartPointerBase& ptr, const char* desc);
199
203template <class T>
204void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr, const char* desc)
205{
206 vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
207}
208
209#endif
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()
Push/Pop whether to do deferred collection.
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()
Set/Get global garbage collection debugging flag.
friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
abstract base class for most VTK objects
Definition: vtkObject.h:82
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 *)