One of the main reasons that my app still occasionally crashes is that I have limited control over Android's heap management. In particular, when I launch a new activity from within my app, I see in the DDMS debug view for my dev phone 1 a huge - albeit temporary - free memory dip that sometimes measures over 2MB, and the free memory as a result going down to a mere several hundred KB is then occasionally the reason that the camera preview internally (not in my Android code!) cannot allocate the 230400 bytes needed for a preview image. I cannot catch this internal OutOfMemory exception to prevent an application crash because it occurs in the lower level camera code, not in my own application-level memory allocations and preview processing.
The newly launched activity that causes the free memory dip itself does not use much memory (maybe 0.5 MB), and after a second or so I therefore again have at least 3 MB free memory, so I conclude that it is in the transition between two activities (the main one and the startActivityForResult()-launched one) that the memory dip occurs. My app does not leak memory, as is evident from the fact that free memory remains approximately constant even when I run my app for a long time. Normally I have between 3 MB and 3.5 MB free memory while running my app, at a DDMS-reported heap size of 5.6 MB (apparently Android process management already takes a huge bite out of the 16 MB total heap that any app is supposed to have?). I also apply System.gc() and Bitmap.recycle() in my code where big memory blocks such as for bitmaps are allocated/freed, and I apply try-catch blocks to catch OutOfMemoryError exceptions arising from my own code to transparently recover from temporary memory dips without a crash, because those OutOfMemoryError exceptions arise from Android not cleaning up in time - but again, I just cannot catch Android's lower level memory allocation problems that still cause my app to crash. :-( Is there a way to prevent the large - though temporary - free memory dips that occur when a new activity is launched? It looks as if Android cleans up for the launching app only *after* the new activity has been fully launched, and acts much like there are temporarily two complete activities plus transition management overhead in memory as far as heap usage is concerned? It is pretty bad if one cannot trust memory management when this causes unpredictable application crashes due to things that lie beyond the reach of the application programmer. Thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---