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.

你可能感兴趣的:(android)