VTK  9.0.20200704
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;
99  static vtkGarbageCollector* New();
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:
150  ~vtkGarbageCollector() override;
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
210 // VTK-HeaderTest-Exclude: vtkGarbageCollector.h
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:32
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkObjectBase
abstract base class for most VTK objects
Definition: vtkObjectBase.h:69
vtkGarbageCollectorReportInternal
void VTKCOMMONCORE_EXPORT vtkGarbageCollectorReportInternal(vtkGarbageCollector *, vtkObjectBase *, void *, const char *)
vtkGarbageCollectorManager.h
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkGarbageCollector
Detect and break reference loops.
Definition: vtkGarbageCollector.h:94
vtkObject.h
vtkGarbageCollectorManager
Manages the vtkGarbageCollector singleton.
Definition: vtkGarbageCollectorManager.h:34