On Thu, Jun 10, 2010 at 8:18 AM, Bob Kerns <r...@acm.org> wrote: > What I was trying to get at is that if you're relying on System.gc(), > you're skating on the edge, memory-wise, tweaking the exact behavior > of the GC. > > I didn't mean to suggest it's not helpful; I've followed with interest > your reports of your experience. But I'd characterize calling > System.gc() as an optimization hack, not a workaround for a system > problem. > > By all means, do the extra GC. It can make the difference between a > useful and useless app. > > I was really responding to Stephen's comment: > "Is Dalvik such a crappy virtual machine that it can't be bothered to > run the garbage collector before spitting out an OutOfMemory > exception? " > > To which the answer is, "no, detects it when it runs the GC. But > sometimes in special cases, an extra GC can free up memory that the > first one couldn't". > > Could DalvicVM handle bitmaps better? Yes. But I wouldn't call it a > "crappy VM", and it runs the GC before failing. >
And that was the whole point. In fact, the posted algorithm could try to get into a loop, running the GC and trying to load the bitmap again, until it succeeded (not likely) or the VM crashed and it would be equally misguided. I was specifically objecting to that hopeful GC run in an OutOfMemory situation, before allocating a huge data structure again, while in a possibly non-recoverable state. Catching OutOfMemoryError allows one to at least try to cleanup before death - it is not a plugin system for the garbage collector. Now, an explicit GC *before* big allocations could help. This would at the very least allow the VM to free memory (if any) before the fact. I'd take it as a hint to the virtual machine. -- Stephen Sent from my Emacs -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en