Skip to content

Feature: Provide a JS helper function on the global object to release the native object wrapped by a JS instance #1254

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

Closed
vmutafov opened this issue Jan 21, 2019 · 1 comment
Assignees
Labels
feature needs docs Documentation is needed before closing
Milestone

Comments

@vmutafov
Copy link
Contributor

vmutafov commented Jan 21, 2019

Is your feature request related to a problem? Please describe.
When a native object is created from JS code, it’s kept alive by a strong reference in the runtime until the JavaScript object is garbage collected. This can create a memory problem in cases where large objects are instantiated and the JS VM doesn’t collect them after they are practically dead due to low memory pressure in its heap.

Describe the solution you'd like
A new helper function with a signature looking like: __releaseNativeCounterpart(objectToBeReleased), would help in earlier releasing of the strong connection when the user decides the (possibly heavy) native object will no longer be used in JS. This would then enable the Android runtime to garbage collect the object earlier — as long as it doesn’t have any other strong references remaining.

Describe alternatives you've considered
Advise users to trigger a JS garbage collection as soon as they are done using heavy objects. This, however, has some performance drawbacks and implications, meaning that it might not be feasible in all cases.

@vmutafov
Copy link
Contributor Author

Analogous to this feature in the iOS runtime: NativeScript/ios-jsc#1062

@vmutafov vmutafov added this to the 5.2.0 milestone Jan 21, 2019
mbektchiev added a commit to NativeScript/NativeScript that referenced this issue Feb 7, 2019
* Add `releaseNativeObject` function in `utils`
* Add tests
* Add typings for the global `__releaseNativeCounterpart` functions
provided by Android and iOS runtimes

refs NativeScript/ios-jsc#1062 and NativeScript/android#1254
mbektchiev added a commit to NativeScript/NativeScript that referenced this issue Feb 7, 2019
* Add `releaseNativeObject` function in `utils`
* Add tests
* Add typings for the global `__releaseNativeCounterpart` functions
provided by Android and iOS runtimes

refs NativeScript/ios-jsc#1062 and NativeScript/android#1254
mbektchiev added a commit to NativeScript/NativeScript that referenced this issue Feb 7, 2019
* Add `releaseNativeObject` function in `utils`
* Add tests
* Add typings for the global `__releaseNativeCounterpart` functions
provided by Android and iOS runtimes

refs NativeScript/ios-jsc#1062 and NativeScript/android#1254
mbektchiev added a commit to NativeScript/NativeScript that referenced this issue Feb 8, 2019
* Add `releaseNativeObject` function in `utils`
* Add tests
* Add typings for the global `__releaseNativeCounterpart` functions
provided by Android and iOS runtimes

refs NativeScript/ios-jsc#1062 and NativeScript/android#1254
SvetoslavTsenov pushed a commit to NativeScript/NativeScript that referenced this issue Feb 8, 2019
…6873)

* Add `releaseNativeObject` function in `utils`
* Add tests
* Add typings for the global `__releaseNativeCounterpart` functions
provided by Android and iOS runtimes

refs NativeScript/ios-jsc#1062 and NativeScript/android#1254
@vtrifonov vtrifonov added the needs docs Documentation is needed before closing label Feb 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature needs docs Documentation is needed before closing
Projects
None yet
Development

No branches or pull requests

4 participants