1

I'm encountering this problem. I've memory leaks as I start and reboot my app 5 times. It seems that phonegap and the Cordova browser leaves in memory some objects.

07-28 03:48:01.886: E/dalvikvm(10729): Failed adding to JNI local ref table (has 512 entries)
07-28 03:48:01.895: E/dalvikvm(10729): VM aborting
07-28 03:48:01.895: A/libc(10729): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1) 
Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)

As soon the app crashesh I can normally restart the app again and it works for other 5 times. So how can I normally kill my app so to remove all javascript in memory ?

// about 116 script elements
que.forEach(function (f, i) {
    var s = d.createElement('script');
    s.async = false;
    s.src = f;
    s.onload = function () {
        loaded++;
        p = loaded / que.length;
        //TODO: code for updating progress bar
    };
    d.body.appendChild(s);
    que[i] = s;

});

This didn't solve the problem too:

for (var i = tags.length; i >= 0; i--){ //search backwards within nodelist   for matching elements to remove
             if (tags[i] && tags[i].getAttribute('src') != null) {
                  tags[i].parentNode.removeChild(tags[i]); //remove element by calling parentNode.removeChild()
                  for (var prop in tags[i]) {
                      delete tags[i][prop];
                    }
             }
         }
Claudio Ferraro
  • 4,551
  • 6
  • 43
  • 78
  • I dnt know how to code in javascript but I too had the same problem and solved that by using MAT and following proper lifecycle for android. set all the object to null before calling on destroy and setting the intent flag to nohistory. – baloo Jul 29 '13 at 04:37
  • the code is cocos2d code..It loads 116 Script tags dynamically. I edited the question – Claudio Ferraro Jul 29 '13 at 04:52
  • What do you mean with MAT ..which objects should I set to null. Can you provide some more explanations please – Claudio Ferraro Jul 29 '13 at 04:54
  • I partially solved using System.exit(0) but I don't think this should be a best practice – Claudio Ferraro Jul 29 '13 at 04:54
  • [you need to kill appication process](http://stackoverflow.com/questions/2092951/how-to-close-android-application). But this isn't android way. – Leonidos Jul 29 '13 at 06:06
  • MAT is memory analyzing tool which will help you finding the leaks . – baloo Jul 29 '13 at 07:11
  • use System.gc() instead, although you can't be sure if it will work as thats a low priority thread. – baloo Jul 29 '13 at 07:14
  • System.gc() doesn't work. I tried even to remove with javascript all the script elements from the dom before closing but nothing! – Claudio Ferraro Jul 29 '13 at 11:37
  • baloo can you please tell me how do you set all the objects to null ? – Claudio Ferraro Jul 29 '13 at 11:53

1 Answers1

0

call this method in onCreate method this worked for me ->

super.setBooleanProperty("keepRunning", false);