I have read Android’s Developers Guide on Designing for Performance.
I am just wondering that if I have a large object, that I cannot avoid creating (which is expensive ) , it seems logical that I want to deallocate it immediately when I know I am done with it.
There seems to be no way of doing this.
Some suggest setting it to null so it will be immediately GC by the system, will this be truely “immediate”? Because if the system (Dalvik VM) has the option to NOT deallocate the large object that I just set to null, then setting it to null is not at all a solution.
Is it correct to say that setting it to null will ENCOURAGE and SPEED up GC?
Is this approach a “good enough” way to optimize Apps performance? Or is it worth going the extra mile (if at all possible ) , to force GC whenever applicable to squeeze the best performance out of any Android device?
I don’t think you should worry to the granular details when GC is executed as we don’t have control over when gc gets called. Even calling gc() will not guarantee a collection. Per documentation from System.gc()
In developing the application with large object allocation I would worry about the following instead: