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

Add support for weak references #1172

Merged
merged 1 commit into from
May 10, 2022

Conversation

devongovett
Copy link
Contributor

This adds support for a WeakReference type, which is similar to Reference but does not increment the napi reference count. This is useful in cases where you need to avoid a cycle, e.g. a parent object with a reference to a child, which also has a reference back to the parent. Just using Reference for this results in the objects never being garbage collected.

A WeakReference can be created from a Reference using the downgrade method, and either returned from an napi function by cloning, or converted back to a strong reference with the upgrade method. This API is inspired by the Rust Rc and Weak types.

@Brooooooklyn Brooooooklyn merged commit 57ea8dc into napi-rs:main May 10, 2022
@devongovett devongovett deleted the weak-reference branch May 13, 2022 02:25
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.

2 participants