Read now

Clear Bitmap stored memory

We will need to release heap memory because for each application has the limited amount of memory usage of RAM, so we recommended to release memory i.e not require further.

We are discussing in this blog how to release Bitmap allocated memory when further Bitmap not required in the running Application. Bitmap usage large amount of RAM memory, so we have got many times OutOfMemoryError Exception.

On Android 2.3.3 (API level 10) and lower, the backing pixel data for a bitmap is stored in native memory. It is separate from the bitmap itself, which is stored in the Dalvik heap. The pixel data in native memory is not released in a predictable manner, potentially causing an application to briefly exceed its memory limits and crash. As of Android 3.0 (API level 11), the pixel data is stored on the Dalvik heap along with the associated bitmap.

In given code, here I am uploading multiple bitmap images on the server through the multipart request, Image URIs is stored in ImageData class. Now We get the Bitmap Image from the URI and then compress/write Image bytes into ByteArrayOutputStream when all the process has done then We recommended to release allocated memory. because the first bitmap is not GC’ed when we decode the second one. GC will do it later whenever it decides. The recycle() method release the allocated bitmap memory.

Different Android versions have different strategies to release Bitmap memory. for example –


. . .


Add Your Comment

Be the first to comment.

Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again