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=========================================================================*/
75#ifndef vtkGarbageCollector_h
76#define vtkGarbageCollector_h
77
78#include "vtkCommonCoreModule.h" // For export macro
79#include "vtkGarbageCollectorManager.h" // Needed for singleton initialization.
80#include "vtkObject.h"
81
82// This function is a friend of the collector so that it can call the
83// internal report method.
84void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
85 vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
86
87// This allows vtkObjectBase to get at the methods it needs.
88class vtkObjectBaseToGarbageCollectorFriendship;
89
90class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
91{
92public:
94 void PrintSelf(ostream& os, vtkIndent indent) override;
96
109 static void Collect();
110
122 static void Collect(vtkObjectBase* root);
123
125
134
136
140 static void SetGlobalDebugFlag(bool flag);
141 static bool GetGlobalDebugFlag();
143
144protected:
147
148private:
159 static int GiveReference(vtkObjectBase* obj);
160
169 static int TakeReference(vtkObjectBase* obj);
170
171 // Singleton management functions.
172 static void ClassInitialize();
173 static void ClassFinalize();
174
176 friend class vtkObjectBaseToGarbageCollectorFriendship;
177
178 // Internal report callback and friend function that calls it.
179 virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
180 friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
181 vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
182
183private:
185 void operator=(const vtkGarbageCollector&) = delete;
186};
187
189
193void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(
194 vtkGarbageCollector* collector, vtkSmartPointerBase& ptr, const char* desc);
195
199template <class T>
200void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr, const char* desc)
201{
202 vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
203}
204
205#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:40
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:63
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 *)