Android sdk > 2.1.0 Excessive JNI global references

You must Login before you can answer or comment on any questions.

Android sdk r20.0.3 + Titanium sdk > 2.1.0 - app terminates (even when idle); log displays low memory, last 10 jni global refs, then:

WARN][dalvikvm( 305)] Memory held directly by tracked refs is 43548 bytes [ERROR][dalvikvm( 305)] Excessive JNI global references (2001) [ERROR][dalvikvm( 305)] VM aborting

However, 2.1.0 sdk works fine.

2 Answers

It seems that there is a problem with Android emulator when you use a simple WebView, with Android API < 4.0. As soon as the WebView is opened/loaded in the active window, and with no further interaction (just let it sit there), it will start leaking memory. You can see this by watching the Console and noticing other Android processes dieing off, and then eventually the app itself will crash. An easier way to see the memory leak is to connect your emulator process to DDMS and view the log. Note you will see GREF has increased to XYZ every few seconds, where XYZ increases by 100 each time, till it hits 2001 at which point that is the max JNI GREFs allowed and the app dies. GREF are global references that cannot be garbage collected, and for whatever reason the WebView is causing these to be created.

Try running the very simple code below in app.js on Android emulator to reproduce the problem. Make sure to pick Android API < 4.0. Apparently at API 4+ this no longer happens, as far as I can tell.

var win = Ti.UI.createWindow();
var wv = Ti.UI.createWebView({url:'http://www.google.com'});
win.add(wv);
win.open();
Note that this doesn't seem to happen on an Android device. In my tests, the memory of the testing app remains stable on the device, it is only an emulator problem (but of course this is annoying for development).

Also note that the same issue happens in Kitchen Sink on Android emulator, if you go to Base UI->Views->Webviews and select one of the options. You can connect it to DDMS and watch the GREF count increase until the app crashes. I will probably end up posting this as a bug to JIRA.

Same problem for me with an app with a webview (Android SDK r20.0.3 + Titanium 2.1.3)...

The app start and crash after increasement of GREF

GREF has increased to 1701
GREF has increased to 1801
GREF has increased to 1901
GREF has increased to 2001
Excessive JNI global references (2001)
VM aborting

— answered 8 months ago by Damien Laureaux
answer permalink
1 Comment
  • Wow, I have one window with one view, and it crashes every 4 minutes. 2.3 does not run at all. So I can develop with 2.1, but will have to live without V8, or develop with 4+. That's a pretty big spread.

    — commented 6 months ago by Hal Burgiss

Your Answer

Think you can help? Login to answer this question!