NativeScript / ios-jsc

NativeScript for iOS using JavaScriptCore

Home Page:http://docs.nativescript.org/runtimes/ios

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

mbektchiev opened this issue · comments

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 native runtime to deallocate 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.

Analogous to this feature in the Android runtime: NativeScript/android#1254

When try to release var in ts project app crashes

var num = 0;
console.log("num = 0 " + num);

utils.releaseNativeObject(num);
console.log("RELESED!");
console.log("NULL Released: num = 0 " + num);

Here's the log

CONSOLE LOG file:///app/main-view-model.js:40:20: num = 0 0