OLD | NEW |
---|---|
1 # Blink GC API reference | 1 # Blink GC API reference |
2 | 2 |
3 This is a through document for Oilpan API usage. | 3 This is a through document for Oilpan API usage. |
4 If you want to learn the API usage quickly, look at | 4 If you want to learn the API usage quickly, look at |
5 [this tutorial](https://docs.google.com/presentation/d/1XPu03ymz8W295mCftEC9KshH 9Icxfq81YwIJQzQrvxo/edit#slide=id.p). | 5 [this tutorial](https://docs.google.com/presentation/d/1XPu03ymz8W295mCftEC9KshH 9Icxfq81YwIJQzQrvxo/edit#slide=id.p). |
6 | 6 |
7 [TOC] | 7 [TOC] |
8 | 8 |
9 ## Header file | 9 ## Header file |
10 | 10 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 `functionName`. | 170 `functionName`. |
171 | 171 |
172 A pre-finalizer is a user-defined member function of a garbage-collected class t hat is called when the object is going | 172 A pre-finalizer is a user-defined member function of a garbage-collected class t hat is called when the object is going |
173 to be swept but before the garbage collector actually sweeps any objects. Theref ore, it is allowed for a pre-finalizer | 173 to be swept but before the garbage collector actually sweeps any objects. Theref ore, it is allowed for a pre-finalizer |
174 to touch any other on-heap objects, while a destructor is not. It is useful for doing some cleanups that cannot be done | 174 to touch any other on-heap objects, while a destructor is not. It is useful for doing some cleanups that cannot be done |
175 with a destructor. | 175 with a destructor. |
176 | 176 |
177 A pre-finalizer must have the following function signature: `void preFinalizer() `. You can change the function name. | 177 A pre-finalizer must have the following function signature: `void preFinalizer() `. You can change the function name. |
178 | 178 |
179 A pre-finalizer must be registered in the constructor by using the following sta tement: | 179 A pre-finalizer must be registered in the constructor by using the following sta tement: |
180 "`ThreadState::current()->registerPreFinalizer(preFinalizerName);`". | 180 "`ThreadState::current()->registerPreFinalizer(this);`". |
Peter Beverloo
2016/04/13 18:32:28
Do you want to separate out this change (and the c
Michael van Ouwerkerk
2016/04/14 13:42:12
Done.
| |
181 | 181 |
182 ```c++ | 182 ```c++ |
183 class YourClass : public GarbageCollectedFinalized<YourClass> { | 183 class YourClass : public GarbageCollectedFinalized<YourClass> { |
184 USING_PRE_FINALIZER(YourClass, dispose); | 184 USING_PRE_FINALIZER(YourClass, dispose); |
185 public: | 185 public: |
186 YourClass() | 186 YourClass() |
187 { | 187 { |
188 ThreadState::current()->registerPreFinalizer(dispose); | 188 ThreadState::current()->registerPreFinalizer(this); |
189 } | 189 } |
190 void dispose() | 190 void dispose() |
191 { | 191 { |
192 m_other->dispose(); // OK; you can touch other on-heap objects in a pre- finalizer. | 192 m_other->dispose(); // OK; you can touch other on-heap objects in a pre- finalizer. |
193 } | 193 } |
194 ~YourClass() | 194 ~YourClass() |
195 { | 195 { |
196 // m_other->dispose(); // BAD. | 196 // m_other->dispose(); // BAD. |
197 } | 197 } |
198 | 198 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 DEFINE_TRACE(C) | 382 DEFINE_TRACE(C) |
383 { | 383 { |
384 visitor->trace(m_x); | 384 visitor->trace(m_x); |
385 visitor->trace(m_y); // Weak member needs to be traced. | 385 visitor->trace(m_y); // Weak member needs to be traced. |
386 visitor->trace(m_z); // Heap collection does, too. | 386 visitor->trace(m_z); // Heap collection does, too. |
387 B::trace(visitor); // Delegate to the parent. In this case it's empty, but t his is required. | 387 B::trace(visitor); // Delegate to the parent. In this case it's empty, but t his is required. |
388 } | 388 } |
389 ``` | 389 ``` |
390 | 390 |
391 ## Heap collections | 391 ## Heap collections |
OLD | NEW |