| 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 If you're just interested in wrapper tracing, | 6 If you're just interested in wrapper tracing, |
| 7 see [Wrapper Tracing Reference](../../bindings/core/v8/TraceWrapperReference.md)
. | 7 see [Wrapper Tracing Reference](../../bindings/core/v8/TraceWrapperReference.md)
. |
| 8 | 8 |
| 9 [TOC] | 9 [TOC] |
| 10 | 10 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 `USING_PRE_FINALIZER(ClassName, functionName)` in a class declaration declares t
he class has a *pre-finalizer* of name | 171 `USING_PRE_FINALIZER(ClassName, functionName)` in a class declaration declares t
he class has a *pre-finalizer* of name |
| 172 `functionName`. | 172 `functionName`. |
| 173 | 173 |
| 174 A pre-finalizer is a user-defined member function of a garbage-collected class t
hat is called when the object is going | 174 A pre-finalizer is a user-defined member function of a garbage-collected class t
hat is called when the object is going |
| 175 to be swept but before the garbage collector actually sweeps any objects. Theref
ore, it is allowed for a pre-finalizer | 175 to be swept but before the garbage collector actually sweeps any objects. Theref
ore, it is allowed for a pre-finalizer |
| 176 to touch any other on-heap objects, while a destructor is not. It is useful for
doing some cleanups that cannot be done | 176 to touch any other on-heap objects, while a destructor is not. It is useful for
doing some cleanups that cannot be done |
| 177 with a destructor. | 177 with a destructor. |
| 178 | 178 |
| 179 A pre-finalizer must have the following function signature: `void preFinalizer()
`. You can change the function name. | 179 A pre-finalizer must have the following function signature: `void preFinalizer()
`. You can change the function name. |
| 180 | 180 |
| 181 A pre-finalizer must be registered in the constructor by using the following sta
tement: | |
| 182 "`ThreadState::current()->registerPreFinalizer(this);`". | |
| 183 | |
| 184 ```c++ | 181 ```c++ |
| 185 class YourClass : public GarbageCollectedFinalized<YourClass> { | 182 class YourClass : public GarbageCollectedFinalized<YourClass> { |
| 186 USING_PRE_FINALIZER(YourClass, dispose); | 183 USING_PRE_FINALIZER(YourClass, dispose); |
| 187 public: | 184 public: |
| 188 YourClass() | |
| 189 { | |
| 190 ThreadState::current()->registerPreFinalizer(this); | |
| 191 } | |
| 192 void dispose() | 185 void dispose() |
| 193 { | 186 { |
| 194 m_other->dispose(); // OK; you can touch other on-heap objects in a pre-
finalizer. | 187 m_other->dispose(); // OK; you can touch other on-heap objects in a pre-
finalizer. |
| 195 } | 188 } |
| 196 ~YourClass() | 189 ~YourClass() |
| 197 { | 190 { |
| 198 // m_other->dispose(); // BAD. | 191 // m_other->dispose(); // BAD. |
| 199 } | 192 } |
| 200 | 193 |
| 201 private: | 194 private: |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 }; | 454 }; |
| 462 ``` | 455 ``` |
| 463 | 456 |
| 464 Please be very cautious if you want to use a heap collection from multiple threa
ds. Reference to heap collections may be passed to another thread using CrossThr
eadPersistents, but *you may not modify the collection from the non-owner thread
*. This is because modifications to collections may trigger backing store reallo
cations, and Oilpan's per thread heap requires that modifications to a heap happ
en on its owner thread. | 457 Please be very cautious if you want to use a heap collection from multiple threa
ds. Reference to heap collections may be passed to another thread using CrossThr
eadPersistents, but *you may not modify the collection from the non-owner thread
*. This is because modifications to collections may trigger backing store reallo
cations, and Oilpan's per thread heap requires that modifications to a heap happ
en on its owner thread. |
| 465 | 458 |
| 466 ### Weak collections | 459 ### Weak collections |
| 467 | 460 |
| 468 You can put `WeakMember<T>` in heap collections except for `HeapVector` and `Hea
pDeque` which we do not support. | 461 You can put `WeakMember<T>` in heap collections except for `HeapVector` and `Hea
pDeque` which we do not support. |
| 469 | 462 |
| 470 During an Oilpan GC, the weak members that refernce a collected object will be r
emoved from its heap collection, meaning the size of the collection will shrink
and you do not have to check for null weak members when iterating through the co
llection. | 463 During an Oilpan GC, the weak members that refernce a collected object will be r
emoved from its heap collection, meaning the size of the collection will shrink
and you do not have to check for null weak members when iterating through the co
llection. |
| OLD | NEW |