Nativescript: gc() not defined error while closing the nativescript app.

Created on 1 Mar 2017  Â·  11Comments  Â·  Source: NativeScript/NativeScript

When I am closing the app by pressing the back button on android device, it is showing the following error

[" An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to destroy activity {org.nativescript.myapp/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: 
Calling js method onDestroy failed

ReferenceError: gc is not defined
File: "file:///data/data/org.nativescript.myapp/files/app/tns_modules/tns-core-modules/ui/frame/frame.js, line: 726, column: 18

StackTrace: 
    Frame: function:'onActivityDestroyed', file:'file:///data/data/org.nativescript.myapp/files/app/tns_modules/tns-core-modules/application/application.js', line: 35, column: 13
    Frame: function:'ActivityCallbacksImplementation.onDestroy', file:'file:///data/data/org.nativescript.myapp/files/app/tns_modules/tns-core-modules/ui/frame/frame.js', line: 726, column: 19
    Frame: function:'NativeScriptActivity.onDestroy', file:'file:///data/data/org.nativescript.myapp/files/app/tns_modules/tns-core-modules/ui/frame/activity.js', line: 25, column: 25 "]

I commented out the gc() call for the onDestroy() function in tns-core-module/application.android.js, as a result the app was not crashing any more but its running into OOM error after restarting of the app.

I also tried adding the gc() form the "util/utils" module in my application, but it is not recognising the function gc.
should I reimplement the gc() function in my application or is there a better way?

did not find the solution in stackoverflow

testing only for android app.

nativescript version │ 2.5.0
tns-core-modules version │ 2.5.0
tns-android version │ 2.5.0

{ npm: '3.10.8',
ares: '1.10.1-DEV',
http_parser: '2.7.0',
icu: '57.1',
modules: '51',
node: '7.0.0',
openssl: '1.0.2j',
uv: '1.9.1',
v8: '5.4.500.36',
zlib: '1.2.8' }

how to recreate the issue

[EDIT:]
my app uses lot of memory, so I believe gc() is called only triggered because of that.

android question

Most helpful comment

@NickIliev Thanks for the update. We found that this is happening because of missing v8flag in app's package.json. ( "v8Flags": "--expose_gc" )

Not sure how I it happened with sample app as well.

Can close this issue.

All 11 comments

+1

Hey @faisal3389 , @praveenpenumaka

I've tested the described case but was not able to reproduce it. Here are the steps I've taken using NativeScript 2.5.2

tns create myApp --tsc
tns run android

And after the app started I've navigated with the Android back button. The app is closing as expected.

Can you please provide a sample project and/or give more details on what device you are testing (API level)

+1

@NickIliev will GC be triggered in every scenario of app closing Or only when app uses lot of memory? Because above scenario is reproduced only after using application a bit.

@praveenpenumaka GC will be triggered by both low memory event and on Android activity destroyed.

Still the code above is tested with multiple scenarios so it should not cause any trouble - can you please provide us with a sample project which can reproduce this case?

@NickIliev We are trying to reproduce this issue with simple app.

In the mean time, Can you let us know if there is any scenario where nativescript loses scope of V8's gc during runtime?

@NickIliev I was not able replicate exact issue, But I am able to get scope issue for gc by explicitly calling gc in app suspend. You can reproduce scope issue with this repo.

https://github.com/praveenpenumaka/NativeScriptMyApp

@praveenpenumaka thank you for creating and sending a sample project!
I've tested it on my side on real devices (Nexus 5 w/API-23 and Nexus 5x w/API-25) and on an emulator (API19) but still wasn't able to reproduce the error. The application goes in and out of suspend mode with no problems.

Can you please provide the model of the device you are testing on?

@NickIliev Thanks for the update. We found that this is happening because of missing v8flag in app's package.json. ( "v8Flags": "--expose_gc" )

Not sure how I it happened with sample app as well.

Can close this issue.

@praveenpenumaka thanks for the update!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings