VTK  9.2.6
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=========================================================================*/
72#ifndef vtkGarbageCollector_h
73#define vtkGarbageCollector_h
74
75#include "vtkCommonCoreModule.h" // For export macro
76#include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
77#include "vtkObject.h"
78
79// This function is a friend of the collector so that it can call the
80// internal report method.
81void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
82 vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
83
84// This allows vtkObjectBase to get at the methods it needs.
85class vtkObjectBaseToGarbageCollectorFriendship;
86
87class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
88{
89public:
91 void PrintSelf(ostream& os, vtkIndent indent) override;
93
106 static void Collect();
107
119 static void Collect(vtkObjectBase* root);
120
122
131
133
137 static void SetGlobalDebugFlag(bool flag);
138 static bool GetGlobalDebugFlag();
140
141protected:
144
145private:
156 static int GiveReference(vtkObjectBase* obj);
157
166 static int TakeReference(vtkObjectBase* obj);
167
168 // Singleton management functions.
169 static void ClassInitialize();
170 static void ClassFinalize();
171
173 friend class vtkObjectBaseToGarbageCollectorFriendship;
174
175 // Internal report callback and friend function that calls it.
176 virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
177 friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
178 vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
179
180private:
182 void operator=(const vtkGarbageCollector&) = delete;
183};
184
186
190void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(
191 vtkGarbageCollector* collector, vtkSmartPointerBase& ptr, const char* desc);
192
196template <class T>
197void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr, const char* desc)
198{
199 vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
200}
201
202#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:34
abstract base class for most VTK objects
friend class vtkGarbageCollector
Some classes need to clear the reference counts manually due to the way they work.
abstract base class for most VTK objects
Definition vtkObject.h:57
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 *)