VTK  9.0.20210409
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.
88 void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(
89  vtkGarbageCollector*, vtkObjectBase*, void*, const char*);
90 
91 // This allows vtkObjectBase to get at the methods it needs.
92 class vtkObjectBaseToGarbageCollectorFriendship;
93 
94 class VTKCOMMONCORE_EXPORT vtkGarbageCollector : public vtkObject
95 {
96 public:
98  void PrintSelf(ostream& os, vtkIndent indent) override;
100 
113  static void Collect();
114 
126  static void Collect(vtkObjectBase* root);
127 
129 
135  static void DeferredCollectionPush();
136  static void DeferredCollectionPop();
138 
140 
144  static void SetGlobalDebugFlag(bool flag);
145  static bool GetGlobalDebugFlag();
147 
148 protected:
151 
152 private:
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 
187 private:
188  vtkGarbageCollector(const vtkGarbageCollector&) = delete;
189  void operator=(const vtkGarbageCollector&) = delete;
190 };
191 
192 class vtkSmartPointerBase;
193 
197 void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(
198  vtkGarbageCollector* collector, vtkSmartPointerBase& ptr, const char* desc);
199 
203 template <class T>
204 void vtkGarbageCollectorReport(vtkGarbageCollector* collector, T*& ptr, const char* desc)
205 {
206  vtkGarbageCollectorReportInternal(collector, ptr, &ptr, desc);
207 }
208 
209 #endif
vtkGarbageCollector::New
static vtkGarbageCollector * New()
vtkGarbageCollectorReport
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReport(vtkGarbageCollector *collector, vtkSmartPointerBase &ptr, const char *desc)
Function to report a reference held by a smart pointer to a collector.
vtkSmartPointerBase
Non-templated superclass for vtkSmartPointer.
Definition: vtkSmartPointerBase.h:33
vtkGarbageCollector::Collect
static void Collect()
Collect immediately using any objects whose collection was previously deferred as a root for the refe...
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:63
vtkGarbageCollector::~vtkGarbageCollector
~vtkGarbageCollector() override
vtkGarbageCollector::SetGlobalDebugFlag
static void SetGlobalDebugFlag(bool flag)
Set/Get global garbage collection debugging flag.
vtkGarbageCollector::DeferredCollectionPop
static void DeferredCollectionPop()
vtkGarbageCollector::DeferredCollectionPush
static void DeferredCollectionPush()
Push/Pop whether to do deferred collection.
vtkGarbageCollector::vtkGarbageCollector
vtkGarbageCollector()
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:70
vtkGarbageCollectorReportInternal
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
vtkGarbageCollectorManager.h
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:34
vtkGarbageCollector::GetGlobalDebugFlag
static bool GetGlobalDebugFlag()
vtkGarbageCollector::vtkGarbageCollectorReportInternal
friend void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:95
vtkObject.h
vtkGarbageCollector::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGarbageCollectorManager
Manages the vtkGarbageCollector singleton.
Definition: vtkGarbageCollectorManager.h:35
vtkGarbageCollector::Collect
static void Collect(vtkObjectBase *root)
Collect immediately using the given object as the root for a reference graph walk.