java - OutOfMemoryException when going back and forth between activities, despite recycling all Bitmaps and collecting garbage -



java - OutOfMemoryException when going back and forth between activities, despite recycling all Bitmaps and collecting garbage -

this seems simple issue, can't figure out what's causing it.

i have 1 activity creates several bitmaps using bitmap.createbitmap(width, height, config), applies canvas them, , draws on canvases. 1 time i'm done, recycle them. created in resolution displayed at, , don't have issues beingness created. in onsurfacedestroyed(), recycle every bitmap. part of drawing instructions, allocate temporary bitmaps recycled unneeded. measure, set system.gc() in every activity's onsurfacedestroyed().

now, when switch between activity , activity (which creates no bitmaps), outofmemoryexception after 6 or 7 switches , forth. logcat makes clear each time create first activity, more , more space beingness freed automatic garbage collector. here source error:

06-23 12:49:53.984: e/dalvikvm-heap(8487): out of memory on 1382416-byte allocation.

i realize huge byte allocation, don't understand why? has no problem first 5-6 times, why memory seem accumulate though i'm recycling everything? i'm nil else i'm doing high-memory.

i did find work-around using config.rgb_565 create bitmaps instead of config.argb_8888, increases back-and-forth-til-crash count 6-7 around 30. it's still accumulating memory unknown reason.

is there other recycle() can use, or other scheme resource help?

it has no problem first 5-6 times, why memory seem accumulate though i'm recycling everything?

it doesn't accumulate. fragments. on java, outofmemoryerror literal: there not plenty heap space allocate desired block. on android's dalvik vm, outofmemoryerror thereisnoblockbigenougherror, because dalvik not have compacting garbage collector. go more means (and new fine art runtime should have impact) in a blog post.

is there other recycle() can use, or other scheme resource help?

step #1: set android:minsdkversion 11 or higher.

step #2: stop recycling bitmaps. reuse them, using inbitmap on bitmapfactory.options. maintain own pool of available bitmap objects eligible recycling each image resolution needing. see this bit of documentation more.

java android memory bitmap garbage-collection

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -