简体   繁体   中英

How to clear the bitmaps when back is pressed (Java OOM error)?

My application uses many large images. Instead of requesting the use of native memory, I want to clear the bitmaps on back pressed. Android Manifest already states the required use of largeHeap so that's not an issue. The problem is the sheer amount of bitmaps. Can this be done using the back button?

I am getting the java out of memory error. The bitmap combined size exceeds the memory allocated even when largeHeap is enabled.

Update: Each activity has it's own bitmap. When the application reaches around 10 activities, 10 bitmaps, that's when the out of memory error is show.

在开始新activity之前,对所有使用的图像尝试bitmap.recycle()

Use SoftReference to save the Bitmap . When the memory is not enough , GC will clear it or you can try to use the bitmap.recycle() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM