Reputation: 2568
all, I meet a out of memory exception on my phone(4.4.4 MotoX). After take photo, I read it from sdcard-path, then the exception occurs.
12-18 11:12:47.294 11966-11966/com.geexfinance.geexfinance E/dalvikvm-heap﹕ Out of memory on a 42024976-byte allocation.
12-18 10:15:42.099 12905-12905/com.geexfinance.geexfinance E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.geexfinance.geexfinance, PID: 12905
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStreamInternal(BitmapFactory.java:620)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:634)
at com.geexfinance.geexfinance.model.GeexCache.getBitmap(GeexCache.java:1825)
at com.geexfinance.geexfinance.model.GeexCache.getBitmap(GeexCache.java:1940)
at com.geexfinance.geexfinance.ui.GeexApplyInstallmentFragment.onActivityResult(GeexApplyInstallmentFragment.java:532)
at android.app.Activity.dispatchActivityResult(Activity.java:5450)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3428)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3475)
at android.app.ActivityThread.access$1300(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1258)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
It looks strange, I run the same application on a Huawei-pad(4.4.3), OOM never occurs.
I watch the memory-monitor of ANDROID_STUDIO. On my phone , memory allocated from 32MB to 90MB,and OOM exception always occurs when it is about 48MB.on my pad, memory allocated from 32MB to 40MB, never meet a OOM.
I have some questions:
Upvotes: 0
Views: 491
Reputation: 2393
may be it needs large heap, try to write in AndroidManifest.xml
android:largeHeap="true"
Upvotes: 0
Reputation: 50548
my phone have 2048MB memory ,why only a 42MB allocation leads a OOM?
Total RAM memory of the device is not related to heap size allocated per application instance.
why OOM occurs when memory is 48MB,it's not a the memory peak.
OOM occurs when the requested memory is over the heap size, as mentioned above.
same application, same user behavior(take 3 photos), why phone have a exception and pad not?
There are many factors associated with NOT being able to reproduce the OOM, could be the photo details and size, could be the current memory consumption of the app at that point of time. Do some reading on how to process large Bitmap
s efficiently, I'm sure the issue will go away.
Upvotes: 1