How come you still have a reference to your bitmap when a new Activity is created? If you have this bitmap somewhere else than within the Activity, then it's perfectly normal that it's not de-allocated when the Activity disappears. In addition, if your Activity is not garbage collected, you probably have a leak somewhere and are holding onto the Activity object.
On Fri, Dec 4, 2009 at 7:19 PM, skominac <stevan.komi...@gmail.com> wrote: > I had a similar issue. Calling "finish()" on Activity does not in > itself deallocate memory allocated in Activity. The reason we notice > this problem with bitmaps is because they are often so large. > > Recycling bitmaps did not work for me either. > > So, instead, when my Activity starts, and before I create a new > bitmap, I do the following check: > > if (bitmap == null) { > bitmap = Bitmap.createBitmap(width, height, > Bitmap.Config.ARGB_8888); > } else { > bitmap.eraseColor(0); // just clear pixels > } > > This way, I reuse the previously allocated bitmap in a subsequent run > of the Activity. (My Activity only needs one bitmap.) > > Not sure if this is the best way to do it, but it works for me. > > -S. > > On Nov 25, 11:43 am, Matt Hall <matt.h...@gmail.com> wrote: >> Yeah, we've had a similar issue before. One thing you can try is to call >> recycle() on the last frame of your animation before you replace it. This is >> normally called by the garbage collector and works fine when you're not >> close to the memory limit, but it sounds like there might be cases where you >> temporarily go over the limit and the GC doesn't get to the bitmaps in time. >> >> Matt >> >> On Wed, Nov 25, 2009 at 2:37 PM, Matt Kanninen <mathias...@gmail.com> wrote: >> > Matt, >> >> > So in this case I definitely am frequently loading and unloading small >> > images. Those 10 id's all point at different states in our >> > animation. I can reduce the quality of our animation by reducing the >> > views, and decrease how often I stumble down this cow path: >> >> > but I only posted this stack trace because it was new, this happens >> > anytime my app is run for more then half an hour, or 5 mins on the >> > droid. The droid uses the same apk, same images, and 2 slightly >> > different xmls (we added margins to our Droid xml). >> >> >http://groups.google.com/group/android-developers/browse_thread/threa... >> >> > or to quote myself: >> > " >> > If my app runs for more then half an hour on the G1 it will fail on >> > inflating views from xml, giving an error about insufficient memory >> > creating a bitmap. Another issue, which may be a side effect is that >> > global static strings that are assigned at startup become null. >> >> > I have worked around that by throwing up setters around those statics >> > that also store them as a private preference, and thrown up getters >> > that read the preference in case of null. >> >> > The root cause of all of my issues may be that when I call release on >> > my MediaRecorder it sometimes hangs. No crash it just never returns, >> > stalling the thread. I have worked around that by calling release in >> > a thread that only does that. >> >> > Is anyone else seeing and working around issues like these? I could >> > use some advice. >> > " >> >> > -Matt K >> >> > On Nov 25, 10:07 am, Matt Hall <matt.h...@gmail.com> wrote: >> > > How big (dimensions) are the graphics Matt? If they're not very big >> > > then I'm guessing you have bitmap memory used elsewhere in the app >> > > that's putting you close to the max. Bitmap memory is different than >> > > your heap memory, so it's management is hidden from you a little more >> > > but basically this error means you have too many graphics loaded at >> > > once, or are unloading and loading a lot of graphics in a row so the >> > > finalizer can't reclaim the bitmap memory in time. >> >> > > Matt >> >> > > On Nov 25, 12:46 pm, Matt Kanninen <mathias...@gmail.com> wrote: >> >> > > > <a href="http://code.google.com/p/android/issues/detail?id=5045">Issue >> > > > 5045</a> >> >> > > >http://code.google.com/p/android/issues/detail?id=5045 >> >> > > > On Nov 25, 9:37 am, Matt Kanninen <mathias...@gmail.com> wrote: >> >> > > > > This: >> > > > > private static final int[] glowDrawableIds={ >> > > > > R.drawable.graphic_microphoneglow_01, >> > > > > R.drawable.graphic_microphoneglow_02, >> > > > > R.drawable.graphic_microphoneglow_03, >> > > > > R.drawable.graphic_microphoneglow_04, >> > > > > R.drawable.graphic_microphoneglow_05, >> > > > > R.drawable.graphic_microphoneglow_06, >> > > > > R.drawable.graphic_microphoneglow_07, >> > > > > R.drawable.graphic_microphoneglow_08, >> > > > > R.drawable.graphic_microphoneglow_09, >> > > > > R.drawable.graphic_microphoneglow_10 >> > > > > }; >> > > > > ... >> > > > > View glow = findViewById(R.id.glow); >> > > > > .. >> >> > > > > glow.setBackgroundResource(glowDrawableIds[scale]); >> >> > > > > is causing >> >> > > > > 11-25 09:21:02.046: WARN/UsageStats(1018): Failed to persist new >> > stats >> > > > > 11-25 09:21:02.694: DEBUG/dalvikvm(2386): GC freed 298 objects / >> > 15656 >> > > > > bytes in 61ms >> > > > > 11-25 09:21:02.952: ERROR/dalvikvm-heap(2386): 1111680-byte external >> > > > > allocation too large for this process. >> > > > > 11-25 09:21:02.952: ERROR/(2386): VM won't let us allocate 1111680 >> > > > > bytes >> > > > > 11-25 09:21:02.952: DEBUG/AndroidRuntime(2386): Shutting down VM >> > > > > 11-25 09:21:02.952: WARN/dalvikvm(2386): threadid=3: thread exiting >> > > > > with uncaught exception (group=0x4001b180) >> > > > > 11-25 09:21:02.952: ERROR/AndroidRuntime(2386): Uncaught handler: >> > > > > thread main exiting due to uncaught exception >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): >> > > > > java.lang.OutOfMemoryError: bitmap size exceeds VM budget >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.Bitmap.nativeCreate(Native Method) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.Bitmap.createBitmap(Bitmap.java:468) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.Bitmap.createBitmap(Bitmap.java:435) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:462) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> >> > android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java: >> > > > > 323) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.graphics.drawable.Drawable.createFromResourceStream >> > > > > (Drawable.java:697) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.content.res.Resources.loadDrawable(Resources.java:1705) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.content.res.Resources.getDrawable(Resources.java:580) >> > > > > 11-25 09:21:03.014: ERROR/AndroidRuntime(2386): at >> > > > > android.view.View.setBackgroundResource(View.java:7187) >> >> > -- >> > 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<android-developers%2bunsubscr...@googlegroups.com> >> > For more options, visit this group at >> >http://groups.google.com/group/android-developers?hl=en >> >> > > -- > 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 > -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them -- 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