-->

[Kotlin] Android OutOfMemoryError 

 

Process: com.ming.gu, PID: 28384
java.lang.OutOfMemoryError: Failed to allocate a 31961100 byte allocation with 16774160 free bytes and 16MB until OOM
	at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
	at android.graphics.Bitmap.nativeCreate(Native Method)
	at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
	at android.graphics.Bitmap.createBitmap(Bitmap.java:948)
	at android.graphics.Bitmap.createBitmap(Bitmap.java:879)
	at com.ming.gu.function.CustomCapturePad$Companion.rotateImage(CustomCapturePad.kt:203)
	at com.ming.gu.function.CustomCapturePad.onActivityResult(CustomCapturePad.kt:173)
	at com.ming.gu.document.EvidenceDocuFragment.onActivityResult(EvidenceDocuFragment.kt:240)
	at androidx.fragment.app.FragmentManager$9.onActivityResult(FragmentManager.java:2889)
	at androidx.fragment.app.FragmentManager$9.onActivityResult(FragmentManager.java:2869)
	at androidx.activity.result.ActivityResultRegistry.doDispatch(ActivityResultRegistry.java:362)
	at androidx.activity.result.ActivityResultRegistry.dispatchResult(ActivityResultRegistry.java:322)
	at androidx.activity.ComponentActivity.onActivityResult(ComponentActivity.java:634)
	at androidx.fragment.app.FragmentActivity.onActivityResult(FragmentActivity.java:164)
	at android.app.Activity.dispatchActivityResult(Activity.java:7273)
	at android.app.ActivityThread.deliverResults(ActivityThread.java:4520)
	at android.app.ActivityThread.handleSendResult(ActivityThread.java:4567)
	at android.app.ActivityThread.-wrap22(ActivityThread.java)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1695)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:154)
	at android.app.ActivityThread.main(ActivityThread.java:6780)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

흠.. 예전에 만들었던 앱에 무슨 에러가 그렇게 난다길래 보니까 OutOfMemory 에러가 발생했다.

아마 Custom pad를 만들어 사진 캡처하는 기능을 구현했었는데 이미지 처리하던 중 메모리 부족이 발생한 듯.

 

 

1.gradle.properties

#org.gradle.jvmargs=-Xmx2048m
org.gradle.jvmargs=-Xmx4096m

일단 jvm메모리를 2배로 늘려주었다.

 

2. AndroidManifest.xml

android:largeHeap="true"

안드로이드 설정도 바꿔줬다.

 

3.gradle clean

./gradlew clean && ./gradlew : assembleDebug --no-build-cache

 

 

+ Recent posts