Chromium Code Reviews| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 `USING_PRE_FINALIZER(ClassName, functionName)` in a class declaration declares t he class has a *pre-finalizer* of name | 91 `USING_PRE_FINALIZER(ClassName, functionName)` in a class declaration declares t he class has a *pre-finalizer* of name |
| 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: | |
| 102 "`ThreadState::current()->registerPreFinalizer(this, preFinalizerName);`". | |
| 103 | |
| 101 ```c++ | 104 ```c++ |
| 102 class YourClass : public GarbageCollectedFinalized<YourClass> { | 105 class YourClass : public GarbageCollectedFinalized<YourClass> { |
| 103 USING_PRE_FINALIZER(YourClass, dispose); | 106 USING_PRE_FINALIZER(YourClass, dispose); |
| 104 public: | 107 public: |
| 108 YourClass() | |
| 109 { | |
| 110 ThreadState::current()->registerPreFinalizer(this, dispose); | |
|
sof
2015/11/21 16:11:36
ThreadState::registerPreFinalizer() doesn't take t
Yuta Kitamura
2015/11/24 07:07:59
Whoops, thanks. I'll follow-up with this.
(Commen
| |
| 111 } | |
| 105 void dispose() | 112 void dispose() |
| 106 { | 113 { |
| 107 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. |
| 108 } | 115 } |
| 109 ~YourClass() | 116 ~YourClass() |
| 110 { | 117 { |
| 111 // m_other->dispose(); // BAD. | 118 // m_other->dispose(); // BAD. |
| 112 } | 119 } |
| 113 | 120 |
| 114 private: | 121 private: |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 DEFINE_TRACE(C) | 311 DEFINE_TRACE(C) |
| 305 { | 312 { |
| 306 visitor->trace(m_x); | 313 visitor->trace(m_x); |
| 307 visitor->trace(m_y); // Weak member needs to be traced. | 314 visitor->trace(m_y); // Weak member needs to be traced. |
| 308 visitor->trace(m_z); // Heap collection does, too. | 315 visitor->trace(m_z); // Heap collection does, too. |
| 309 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. |
| 310 } | 317 } |
| 311 ``` | 318 ``` |
| 312 | 319 |
| 313 ## Heap collections | 320 ## Heap collections |
| OLD | NEW |