google / cameraview

[DEPRECATED] Easily integrate Camera features into your Android app
Apache License 2.0
4.74k stars 1.03k forks source link

OutOfMemory onCameraOpened #241

Closed OleksandrGrument closed 5 years ago

OleksandrGrument commented 6 years ago

Hi, got a crush on some device in method onCameraOpened. Here is the stacktrace :

0. Crashed: background

   at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
   at android.graphics.Bitmap.nativeCreate(Bitmap.java)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:939)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:912)
   at android.graphics.Bitmap.createBitmap(Bitmap.java:843)
   at com.view.common.camera.CameraLicenseActivity$1.onCameraOpened(Unknown Source)
   at com.view.common.camera.CameraLicenseActivity$1$$Lambda$0.run(Unknown Source)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:145)
   at android.os.HandlerThread.run(HandlerThread.java:61)

--

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 51121164 byte allocation with 16777216 free bytes and 46MB until OOM at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java) at android.graphics.Bitmap.nativeCreate(Bitmap.java) at android.graphics.Bitmap.createBitmap(Bitmap.java:939) at android.graphics.Bitmap.createBitmap(Bitmap.java:912) at android.graphics.Bitmap.createBitmap(Bitmap.java:843) at com.view.common.camera.CameraLicenseActivity$1.onCameraOpened(Unknown Source) at com.view.common.camera.CameraLicenseActivity$1$$Lambda$0.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.os.HandlerThread.run(HandlerThread.java:61)

Did someone have the same issue? How to fix it?

OleksandrGrument commented 6 years ago

Still have this bug, for now it occurs on Samsung Galaxy devices with 5 android

HemanthImandi commented 5 years ago

In HUAWEI and samsung devices mostly this crash happening. Any help.

OleksandrGrument commented 5 years ago

As since the cameraview is deprecated and no longer support, I suggest all migrate to camerax

Here is some base examples including cameraview. https://github.com/android/camera

HemanthImandi commented 5 years ago

In camerax library the minsdkversion is 21. But i have to use the camera in very low end devices(minsdkversion 16). Any other solution?

OleksandrGrument commented 5 years ago

Yes, the other solution is to check your application on memory leaks. The OutOfMemory is a marker of a possible memory leak in application.

https://riggaroo.co.za/fixing-memory-leaks-in-android-outofmemoryerror/

The easiest way to find leaks is to use LeakCanary.