| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d863a9d commit e6ff7e6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,7 +207,7 @@ void BaseObject::decrease_refcount() { | |||
| 207 | 207 | unsigned int new_refcount = --metadata->strong_ptr_count; | |
| 208 | 208 | if (new_refcount == 0) { | |
| 209 | 209 | if (metadata->is_detached) { | |
| 210 | - delete this; | ||
| 210 | + OnGCCollect(); | ||
| 211 | 211 | } else if (metadata->wants_weak_jsobj && !persistent_handle_.IsEmpty()) { | |
| 212 | 212 | MakeWeak(); | |
| 213 | 213 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,7 +84,16 @@ void HandleWrap::Close(Local<Value> close_callback) { | |||
| 84 | 84 | ||
| 85 | 85 | ||
| 86 | 86 | void HandleWrap::OnGCCollect() { | |
| 87 | - Close(); | ||
| 87 | + // When all references to a HandleWrap are lost and the object is supposed to | ||
| 88 | + // be destroyed, we first call Close() to clean up the underlying libuv | ||
| 89 | + // handle. The OnClose callback then acquires and destroys another reference | ||
| 90 | + // to that object, and when that reference is lost, we perform the default | ||
| 91 | + // action (i.e. destroying `this`). | ||
| 92 | + if (state_ != kClosed) { | ||
| 93 | + Close(); | ||
| 94 | + } else { | ||
| 95 | + BaseObject::OnGCCollect(); | ||
| 96 | + } | ||
| 88 | 97 | } | |
| 89 | 98 | ||
| 90 | 99 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments