Delayed Garbage Collection

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

Hey all,

I am working on plugging up some nasty memory leaks. I was wondering if there is supposed to be a delay in the garbage collector and if that is normal. I am nulling out the objects I created in my view when I close the view, if I reopen the view it does create a second set of objects in Instruments, but if I wait about 10 seconds or so, the objects go back to the number expected. Is there a way I can adjust or force a garbage collect?

Thanks!

John

5 Answers

Accepted Answer

Yes, in general there is always a delay in GC and not all memory is released at once. By nulling a variable, it's just like you said to GC: "I don't need this memory any more, you can release it". When he will release it you can't know.

People are paranoid because memory is not released when they nulled variables. But I have app that never releases all memory once variables are null and components are removed from closed window. Memory vary during app running and I still didn't managed to crash app due to low memory. IMO, the best approach is to observe memory state during time, if it's constant over time that you can say you don't have memory holes.

— answered 2 years ago by Ivan ┼ákugor
answer permalink
1 Comment
  • Thank you so much! This was exactly what I was looking for. I was taking a look at kitchensink and it seemed to clear out the variables immediately, but I believe that is because they are using a URL method, and I am not

    -John

    — commented 2 years ago by John Donna

From what I know the GC triggers not when you nullify the objects but when he feels like it should (so to speak :) )

Hi,

I would like to recommend to you a module that I have recently published that calls the native java garbage collection:

https://marketplace.appcelerator.com/apps/7916

I use this technique quite a lot in my apps.

hope that helps :)

Hello,

are you doing a manual cleaning of objects? Let's say you created a button like:

var win = Ti.UI.createWindow();
var button = Ti.UI.createButton();
win.add(button);
win.open();
after you are done with the button, you can do:
win.remove(button);
button=null;
to release memory. You can find more info about Memory Management here.

Best,

Mauro

Your Answer

Think you can help? Login to answer this question!