Delayed Garbage Collection

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?



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 4 years ago by Ivan Škugor
    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


      — commented 4 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:

    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();

    after you are done with the button, you can do:


    to release memory. You can find more info about Memory Management here.