Skip to content

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

@vmutafov

Description

@vmutafov

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.

Metadata

Metadata

Labels

featureneeds docsDocumentation is needed before closing

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions