First,GC will not recycle the memory at once you called. Here are some advice from android developer website:
-
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)
-
Try using the context-application instead of a context-activity
-
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
-
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.
本文提供了避免内存泄漏的方法,包括正确使用上下文引用、采用BitmapFactory.Options优化位图加载及使用try-catch处理内存溢出异常。
1068

被折叠的 条评论
为什么被折叠?



