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.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)Launcher 之 图标加框 优化
  2. android 开机流程
  3. android arm debug
  4. android 编译源码不生成odex
  5. 多媒体框架
  6. Android使用DrawLayout,ToolBar和ActionBa
  7. RecyclerView 实现item点击水波纹动画
  8. 线性布局LinearLayout和相对布局Relative
  9. 一分钟实现TextView高亮效果BabushkaText
  10. android两种方式设置EditText不弹出软键