Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: close HandleWraps instead of deleting them in OnGCCollect() #39441

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/base_object-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void BaseObject::decrease_refcount() {
unsigned int new_refcount = --metadata->strong_ptr_count;
if (new_refcount == 0) {
if (metadata->is_detached) {
delete this;
OnGCCollect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this cause behavioral change to other subclasses of BaseObject ? (for example those who do not have custom implementations of OnGCCollect and expects content to be deleted through the old code)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no subclasses other than HandleWrap which have custom OnGCCollect behavior, so, no.

} else if (metadata->wants_weak_jsobj && !persistent_handle_.IsEmpty()) {
MakeWeak();
}
Expand Down
11 changes: 10 additions & 1 deletion src/handle_wrap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,16 @@ void HandleWrap::Close(Local<Value> close_callback) {


void HandleWrap::OnGCCollect() {
Close();
// When all references to a HandleWrap are lost and the object is supposed to
// be destroyed, we first call Close() to clean up the underlying libuv
// handle. The OnClose callback then acquires and destroys another reference
// to that object, and when that reference is lost, we perform the default
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another reference - we reach here when all the references are detached, so what is this another reference?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s a new one. (The reader of this comment can just look up the source code of the referenced function to see it)

// action (i.e. destroying `this`).
if (state_ != kClosed) {
Close();
} else {
BaseObject::OnGCCollect();
}
}


Expand Down