Skip to content

Conversation

@MaxDesiatov
Copy link
Member

No description provided.

@MaxDesiatov MaxDesiatov requested a review from a team November 28, 2021 22:12
Also, in this version of JavaScriptKit we're simplifying the `JSClosure` API. You no longer need to
release instances of this class manually, they're automatically garbage-collected by the browser
after your Swift code no longer has any references to them. This is achieved with the new
`FinalizationRegistry` Web API, for which we had to significantly increase minimum browser versions
Copy link
Member

Choose a reason for hiding this comment

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

Could you note that there is still a cyclic reference issue. e.g.

var button = document.createElement("button")
button.onclick = .object(JSClosure { [button] in
  // this capture makes a reference cycle
  print(button)
})
┌─> JSObject (button in Swift) -> HTMLElement (button in JS) ────┐
└── JSClosure (onclick in Swift) <─> Closure (onclick in JS) <───┘

In this case, when button element will be disappeared from the main DOM tree, it cannot be deallocated, and the onlick closure will be still referenced. So programmers have to cut the cycle by themselves using weak reference.
So we need to mention that FinalizationRegistry doesn't solve the all GC problem but it only solves dangling closure issue.

Copy link
Member

@j-f1 j-f1 left a comment

Choose a reason for hiding this comment

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

Some grammar nits

@MaxDesiatov MaxDesiatov requested a review from a team November 29, 2021 10:06
@MaxDesiatov MaxDesiatov merged commit 7e664c6 into main Nov 29, 2021
@MaxDesiatov MaxDesiatov deleted the 5.5-release branch November 29, 2021 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants