`
gybin
  • 浏览: 264276 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

android memory 优化

 
阅读更多

First,GC will not recycle the memory at once you called. Here are some advice from android developer website:

  1. Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)

  2. Try using the context-application instead of a context-activity

  3. Avoid non-static inner classes in an activity if you don't control their life cycle, use a static inner class and make a weak reference to the activity inside. The solution to this issue is to use a static inner class with a WeakReference to the outer class, as done in ViewRoot and its W inner class for instance

  4. A garbage collector is not an insurance against memory leaks

Second, try to use BitmapFactory.options when you do not very care the quality of the bitmap.

Third, use try catch to process the OutOfMemory exception in catch block.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics