内存抖动:短时间内大量对象被创建,然后又被释放,这种情况如果达到内存的阈值会触发GC
内存泄漏:一些不再使用的垃圾对象,由于引用了还在使用的对象,导致不能被回收,这些垃圾对象多了,就会导致oom。
以上三者,内存溢出最需要注意、内存泄漏次之,内存抖动最后。
3、如何解决oom
3.1有关bitmap
图片显示:加载合适大小的图片,不要总是请求网络大图,有时可以使用缩略图。
及时释放内存
图片压缩
捕获异常
3.2其他方面
listview:convertview/lru
避免在onDraw方法里面执行对象的创建(如果在onDraw方法里面频繁地进行对象的创建,会造成内存突然上升,而在释放这些内存的时候,又会造成频繁地GC,这样就导致内存抖动)
谨慎使用多进程
三、Bitmap
========
1、recycle
public final class Bitmap implements Parcelable {
/**
-
Free the native object associated with this bitmap, and clear the
-
reference to the pixel data. This will not free the pixel data synchronously;
-
it simply allows it to be garbage collected if there are no other references.
-
The bitmap is marked as “dead”, meaning it will throw an exception if
-
getPixels() or setPixels() is called, and will draw nothing. This operation
-
cannot be reversed, so it should only be called if you are sure there are no
-
further uses for the bitmap. This is an advanced call, and normally need
-
not be called, since the normal GC process will free up this memory when
-
there are no more references to this bitmap.
*/
public void recycle() {
if (!mRecycled && mNativePtr != 0) {
if (nativeRecycle(mNativePtr)) {
// return value indic