VTK  9.2.20230205
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.
84 VTK_ABI_NAMESPACE_BEGIN
85 void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
86  vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
87 
88 // This allows vtkObjectBase to get at the methods it needs.
89 class vtkObjectBaseToGarbageCollectorFriendship;
90 
91 class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
92 {
93 public:
95  void PrintSelf(ostream& os, vtkIndent indent) override;
97 
110  static void Collect();
111 
123  static void Collect(vtkObjectBase* root);
124 
126 
132  static void DeferredCollectionPush();
133  static void DeferredCollectionPop();
135 
137 
141  static void SetGlobalDebugFlag(bool flag);
142  static bool GetGlobalDebugFlag();
144 
145 protected:
148 
149 private:
160  static int GiveReference(vtkObjectBase* obj);
161 
170  static int TakeReference(vtkObjectBase* obj);
171 
172  // Singleton management functions.
173  static void ClassInitialize();
174  static void ClassFinalize();
175 
177  friend class vtkObjectBaseToGarbageCollectorFriendship;
178 
179  // Internal report callback and friend function that calls it.
180  virtual void Report(vtkObjectBase* obj, void* ptr, const char* desc);
181  friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
182  vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
183 
184 private:
185  vtkGarbageCollector(const vtkGarbageCollector&) = delete;
186  void operator=(const vtkGarbageCollector&) = delete;
187 };
188 
189 class vtkSmartPointerBase;
190 
194 void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(
195  vtkGarbageCollector* collector, vtkSmartPointerBase& ptr, const char* desc);
196 
200 template <class T>
201 void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr, const char* desc)
202 {
203  vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
204 }
205 
206 VTK_ABI_NAMESPACE_END
207 #endif
Manages the vtkGarbageCollector singleton.
Detect and break reference loops.
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.
static vtkGarbageCollector * New()
friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObjectBase.h:75
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:83
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 *)