How to Avoid OOM in Android

时间:2022-02-25 05:48:45

1.use java reference(strong soft weak phantom)

2.use android:largeHeap="true" above or VMRuntime.getRuntime().setMinimumHeapSize(BIGGER_SIZE);
/system/build.prop
dalvik.vm.heapsize=128m
dalvik.vm.heapgrowthlimit=64m
((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass()

3.Use second process. Declare at AndroidManifest new Service with
android:process=":second"
Exchange between first and second process over BroadcastReceiver

4.you can use native memory (NDK & JNI)

5.bitmap.recycle() or System.gc()

6.LruCache图片缓存