DevBytes: Bitmap Allocation

Android Developers · 43K views · 2013 · 8:15

Open on YouTube

Software performance & optimizationSoftware (other)Mechanical & precision engineeringtutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering or asking about bitmap memory, GC pressure and OutOfMemory errors, as the standard demonstration of inBitmap reuse.

Recommended by 7 people across 7 different months, 2013 to 2016.

What it is

A short Android DevBytes episode from Chet Haase on the Android Developers channel about reusing bitmap memory. It shows how BitmapFactory.Options.inBitmap lets you decode new images into existing bitmaps, which speeds up loading and cuts garbage collection. A sample project accompanies the video.

What people said

Recommends saschoar · 2013-01 · Stack Overflow · on “Viewpager with large bitmaps”

This question just came to my mind again when watching two little tutorials by Chet Haase. They've just been uploaded and cover `inSampleSize` ( [LINK] ) and Bitmap loading performance in general ( [this video] ). Make sure to check if you can use some of the knowledge to optimize your code and to avoid the Exception.

Recommends Luke Sleeman · 2013-02 · Stack Overflow · on “Very high memory consumption on Nexus 7 with Android Jelly Bean”

I am running into the same thing - Unfortunately I suspect it is caused by the fact that the latest versions of android will try and use the 3d accelerator as much as possible - they will take a copy of your image and pass it onto the 3d accelerator when is then used for rendering the actual pixels that the user sees. This is why you are seeing higher memory consumption. As for what can be done about it - unfortunately not much. This higher memory usage results in an overall much smoother UI (This is project butter, which came along in android 4.1). If you have already looked into the various tutorials such as googles displaying bitmaps efficiently [LINK] then all I can suggest is try turnin

Recommends shelll · 2013-02 · Stack Overflow · on “Garbage collection on OpenGL ES thread”

Thanks to this video [this video] there is an easy solution for same sized tiles and targeting Android 3.0 and newer. BitmapOptions.inBitmap [LINK] which will reuse one Bitmap for every new tile, so no more furios GC-ing.

Recommends shelll · 2013-02 · Stack Overflow · on “How to load OpenGL ES textures with almost no visible FPS drop?”

Finally I solved it, but not with native code, nor with EGL_image, but thanks to this video [this video] . Fortunatelly I had almost all textures in 256x256 and I am targeting Android 3.2 and newer, so for this scenario there is an easy solution: BitmapOptions.inBitmap [LINK] which will reuse one Bitmap for every new tile, so no more furios GC-ing. I had to enlarge the few bitmaps that where smaller than 256x256.

Recommends android developer · 2013-03 · Stack Overflow · on “BitmapFactory.Options#outWidth returns different size than actual bitmap”

OK, i've tried the sample again with 9-patch images, and i see that the values shown in the logs are equal and they are predictable according to the density qualifier. I don't remember what i did last time. However, I've noticed that a google video has talked about getting the correct size of a bitmap. Maybe it could help you : [this video]

Recommends android developer · 2013-07 · Stack Overflow · on “Reusing Android bitmaps for loading many images”

first, you are not talking about the SDK, but about the android version as it is shown to end users (honeycomb ,which is 3.x vs gingerbread and below which is 2.x ). the real thing to look at is the API number . the feature you are talking about has started from API11 (honeycomb) , so you can't use it on older devices, unless you get android's code and do the same for your app. here's a tutorial of how to use this cool feature: [this video]

Recommends JRomero · 2013-08 · Stack Overflow · on “When to recycle bitmap in android project?”

As of ICS the need to recycle isn't necessary. There are a few instance where you would want to but considering most listview implementations it probably won't be necessary. You can check out this video by Chet Hasse for more info on reusing bitmaps which would be better if they are the same size. DevBytes: Bitmap Allocation [this video]

Recommends sai · 2013-12 · Stack Overflow · on “Listview with big image is very slow”

Have you checked Bitmap allocation or Managing memory of bitmaps, if not, please check this video and code below the Android developer video: " [this video] ".

Recommends chipopo · 2015-02 · Stack Overflow · on “Android frame by frame live wallpaper animation”

its hard to tell whats wrong without seeing your code or Log. there is a good video about bitmap recycling that might help: [this video]

Cites Emil Adz · 2013-04 · Stack Overflow · on “Is bitmap can be used after it's been garbage collected?”

I was watching this video, that talks about memory allocation for bitmaps and garbage collection: DevBytes: Bitmap Allocation [this video] Chet is talking about how it was managed by the developer prior to SDK 11 by using .recycle() and after SDK 11 it's is managed by the GC . To a more practical case currently I'm writing an application that in one of the Activities I create many fragments which basically hold a scroll-able layout of ImageViews . those Images are created from the device camera. So I encountered the OutOfMemory problem and realized that I had to re-size the Images I got from the camera because the result was really high res and took all my application memory. So now I'm re-sizing