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