`
- 浏览:
1051336 次
-
Android bitmaps and out of memory errors
One of the things I had to learn the hard way on Android is the correct way of handling Bitmaps. And honestly, I wouldn’t have thought this is the right way if someone at Google wouldn’t have suggested it to me.
Every time you create a bitmap, either blank or from a source using BitmapFactory, the full size of that bitmap is loaded into memory. If you have a 24bit, 300×300 pixel bitmap, it will use 24*300*300 bytes, which is approximately 2Mb. Handling that kind of
memory allocated in the java heap space would be slow, so the Android engineers came with the smart solution of allocating and managing that memory natively (using C).
Now, if you know just a little C, you’ll know that all memory allocations have to be done manually, and so are the de-allocations (freeing up the memory). And since java doesn’t have destructors, when would the Bitmap objects you have know how to clear that
memory? They simply don’t, so you need to clear that memory manually, by calling the .recycle() method of your bitmap object. Simple yet game-changing trick.
How you keep track of the bitmaps is up to you, but (just like all of the other variables), avoid using statics. If you REALLY need global objects, extend Application and keep your stuff there.
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
ICON,图标素材,Icons and Bitmaps 图标
Android 开发者网站上 Training 部分,Building Apps with Graphics & Animation -> Displaying Bitmaps Efficiently部分的实例 demo
This is a program for display bitmaps with zooming and scrolling using windows API.
谷歌官方发布
谷歌官方发布
Scroll colored text and bitmaps transparently over a bitmapped background. (176KB)
A smart way of scaling bitmaps (4KB)
A fast-paced guide, full of real-world examples to help you get the best out of the features offered by Redis Who This Book Is For If you are a competent developer with experience of working with data...
Triangle wars is a thrilling demo of story line and trigonomety plus the designing of huge 24-bit bitmaps and the like. Enjoy
Google官方给出的对于OOM缓存Bitmap以及控制使用内存的方法,使用LruCache和DiskCache,很多有名的图片缓存框架如ImageLoader都有参考这个
Android 6.0的官方开发平台上,有4节是专门来讲BitMap优化的,这是其Word文档。
You wanted simple animation and more uses for blending. This tutorial will teach you all of that. You'll notice there's no spinning boxes. The previous lessons covered the basics of OpenGL. Each ...
to look for bitmaps for WinCE Projects?stop here.
主要为大家详细介绍了Android如何高效显示较大Bitmaps的方法,感兴趣的小伙伴们可以参考一下
Android DisplayingBitmaps示例 该存储库已迁移到 。 请检查该仓库以获取将来的更新。 谢谢!
Bitmap Merger is a simple project help you to merge two bitmaps without memory exceptions. The bitmaps are processed in background threads thereby taking the load away from UI thread. Along with merge...
OpenGL is a powerful software interface used to produce high-quality, computer-generated images and interactive applications using 2D and 3D objects, bitmaps, and color images. The OpenGL®...
Smart resize for monochrome bitmaps不失真的改变单色位图的尺寸(38KB)