OLD | NEW |
1 # Blink GC API reference | 1 # Blink GC API reference |
2 | 2 |
3 This document is work in progress. | 3 This document is work in progress. |
4 | 4 |
5 [TOC] | 5 [TOC] |
6 | 6 |
7 ## Header file | 7 ## Header file |
8 | 8 |
9 Unless otherwise noted, any of the primitives explained in this page requires th
e following `#include` statement: | 9 Unless otherwise noted, any of the primitives explained in this page requires th
e following `#include` statement: |
10 | 10 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 `functionName`. | 92 `functionName`. |
93 | 93 |
94 A pre-finalizer is a user-defined member function of a garbage-collected class t
hat is called when the object is going | 94 A pre-finalizer is a user-defined member function of a garbage-collected class t
hat is called when the object is going |
95 to be swept but before the garbage collector actually sweeps any objects. Theref
ore, it is allowed for a pre-finalizer | 95 to be swept but before the garbage collector actually sweeps any objects. Theref
ore, it is allowed for a pre-finalizer |
96 to touch any other on-heap objects, while a destructor is not. It is useful for
doing some cleanups that cannot be done | 96 to touch any other on-heap objects, while a destructor is not. It is useful for
doing some cleanups that cannot be done |
97 with a destructor. | 97 with a destructor. |
98 | 98 |
99 A pre-finalizer must have the following function signature: `void preFinalizer()
`. You can change the function name. | 99 A pre-finalizer must have the following function signature: `void preFinalizer()
`. You can change the function name. |
100 | 100 |
101 A pre-finalizer must be registered in the constructor by using the following sta
tement: | 101 A pre-finalizer must be registered in the constructor by using the following sta
tement: |
102 "`ThreadState::current()->registerPreFinalizer(this, preFinalizerName);`". | 102 "`ThreadState::current()->registerPreFinalizer(preFinalizerName);`". |
103 | 103 |
104 ```c++ | 104 ```c++ |
105 class YourClass : public GarbageCollectedFinalized<YourClass> { | 105 class YourClass : public GarbageCollectedFinalized<YourClass> { |
106 USING_PRE_FINALIZER(YourClass, dispose); | 106 USING_PRE_FINALIZER(YourClass, dispose); |
107 public: | 107 public: |
108 YourClass() | 108 YourClass() |
109 { | 109 { |
110 ThreadState::current()->registerPreFinalizer(this, dispose); | 110 ThreadState::current()->registerPreFinalizer(dispose); |
111 } | 111 } |
112 void dispose() | 112 void dispose() |
113 { | 113 { |
114 m_other->dispose(); // OK; you can touch other on-heap objects in a pre-
finalizer. | 114 m_other->dispose(); // OK; you can touch other on-heap objects in a pre-
finalizer. |
115 } | 115 } |
116 ~YourClass() | 116 ~YourClass() |
117 { | 117 { |
118 // m_other->dispose(); // BAD. | 118 // m_other->dispose(); // BAD. |
119 } | 119 } |
120 | 120 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 DEFINE_TRACE(C) | 311 DEFINE_TRACE(C) |
312 { | 312 { |
313 visitor->trace(m_x); | 313 visitor->trace(m_x); |
314 visitor->trace(m_y); // Weak member needs to be traced. | 314 visitor->trace(m_y); // Weak member needs to be traced. |
315 visitor->trace(m_z); // Heap collection does, too. | 315 visitor->trace(m_z); // Heap collection does, too. |
316 B::trace(visitor); // Delegate to the parent. In this case it's empty, but t
his is required. | 316 B::trace(visitor); // Delegate to the parent. In this case it's empty, but t
his is required. |
317 } | 317 } |
318 ``` | 318 ``` |
319 | 319 |
320 ## Heap collections | 320 ## Heap collections |
OLD | NEW |