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?
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.
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.
From what I know the GC triggers not when you nullify the objects but when he feels like it should (so to speak :) )
Think you can help? Login to answer this question!