When i run my application on a physical device
Every time the application crashes. The LogCat displays "Out of memory and Failed to allocate a 74649612 byte allocation with 16768392 free bytes and 49MB until OOM "
The device I am using is Xiaomi RedMi note 4
3GB RAM
Android version 7.0
Processor Qualcomm Snapdragon 625
Here is the LogCat message
java.lang.OutOfMemoryError: Failed to allocate a 74649612 byte allocation with 16768392 free bytes and 49MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:624)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:457)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
at android.content.res.ResourcesImpl.createFromResourceStream(ResourcesImpl.java:1272)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:743)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:585)
at android.content.res.MiuiResourcesImpl.loadDrawable(MiuiResourcesImpl.java:308)
at android.content.res.Resources.getDrawable(Resources.java:785)
at android.content.res.Resources.getDrawable(Resources.java:756)
at com.suman.udit.su.MainActivity.onCreate(MainActivity.java:52)
at android.app.Activity.performCreate(Activity.java:6852)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2700)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2808)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1541)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:165)
at android.app.ActivityThread.main(ActivityThread.java:6365)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:883)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
Looks like the Drawable (picture, perhaps?) you are trying to load at MainActivity.java:52 is too big. You also might try putting it in the drawable-nodpi folder, so that the system doesn't try to re-scale it upon load.
OutOfMemoryError is the most common problem occured in android while especially dealing with bitmaps. This error is thrown by the Java Virtual Machine (JVM) when an object cannot be allocated due to lack of memory space and also, the garbage collector cannot free some space.
As mentioned by Aleksey, you can add below entities in your manifest file android:hardwareAccelerated="false" , android:largeHeap="true" it will work for some environment's.
<application
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:supportsRtl="true"
android:theme="#style/AppTheme">
you should definately read some of Androids Developer concept's, specially here:Displaying Bitmaps Efficiently
Read all 5 topics and rewrite your code again. If it still doesn't work we will be happy to see what you've done wrong with the tutorial material.
Here some of possible answers for these type of errors in SOF
Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap
How to solve java.lang.OutOfMemoryError trouble in Android
Android : java.lang.OutOfMemoryError
java.lang.OutOfMemoryError
Solution for OutOfMemoryError: bitmap size exceeds VM budget
Related
I am having adobe sitecatalyst in my android application,
and found several crashes with below mentioned stacktrace.
Fatal Exception: java.lang.OutOfMemoryError: int[] of length 1674283432 exceeds the VM limit
at android.util.ArrayMap.allocArrays(ArrayMap.java:196)
at android.util.ArrayMap.ensureCapacity(ArrayMap.java:307)
at android.os.Bundle.unparcel(Bundle.java:247)
at android.os.Bundle.containsKey(Bundle.java:299)
at com.adobe.mobile.ReferrerHandler.getReferrerURLFromIntent(SourceFile:97)
at com.adobe.mobile.ReferrerHandler.processIntent(SourceFile:63)
at com.adobe.mobile.Analytics$10.run(SourceFile:211)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:841)
Somewhere in adobe analytics code, its creating array of bigger size.
Any solution for this ?
I research about the error you faced in your application and I found 2 answers, they all sed to change the javaMaxHeapSize to "4g" inside dexOptions
please check the following link, hope it will work
Android - Java heap space error
android-gradle-what-is-javamaxheapsize-4g
Increase heap size
Try This Application Tag of Manifest file..
<application
android:name=".app.MyApplication"
android:hardwareAccelerated="true"
android:vmSafeMode="true"
android:largeHeap="true">
I've been getting many OOM crashes in my android app (many but not all of them seem to be in Realm code:
First:
io.realm.exceptions.RealmError: Unrecoverable error. mmap() failed: Out of memory size: 872415232 offset: 0 in /Users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
Second:
io.realm.exceptions.RealmError: Unrecoverable error. Too many open files in /Users/zaki/fromgit/realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_SharedRealm.cpp line 92
but also some even more vague memory issues:
java.lang.OutOfMemoryError: Could not allocate JNI Env
These issues seem to only happen in production and watching the memory usage in my app seems to hover pretty consistently around 10MB.
Hi i have been doing a project from school and when i ran my application i have the stack trace error shown below.
03-06 14:58:02.520 11265-11265/com.example.ray.cdmsv2 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
at android.content.res.Resources.loadDrawable(Resources.java:2970)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.TintManager.getDrawable(TintManager.java:147)
at android.support.design.widget.TabLayout$Tab.setIcon(TabLayout.java:1080)
at com.example.ray.cdmsv2.Activities.CreateTaskActivity.onCreate(CreateTaskActivity.java:102)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
I have looked around for solution but i still cannot resolve the issue. My application is able to run smoothly on Samsung Galaxy A3. However when i tried to run my application on a S4 and Note 4 i receive the out of memory error. I have realized that when i implement some selector in my drawable which i call in my XML files, it will cause the error, however when i remove it the error does not occur anymore. Is there any explanation for this issue? Thank you very much for helping me out
Delete the drawable and import it again using ImageAsset option.
The error is your image is too heavy for loading it into memory. Or better compress the image before copying it into the Drawable folder.
I would start by learning some best practices for memory usage by google at the dev docs #
http://developer.android.com/training/displaying-bitmaps/index.html
If you're loading large bitmaps, its quite possible the available heap memory is not enough for your bitmaps.
Your app is being choked by Android because it is using more memory than assigned, primarily due to a large image file being used as a drawable.
If it is an icon, use Android Studio's built in Image Asset generator to generate appropriate image sizes for each display type (mdpi,hdpi,xhdpi,xxhdpi and so on). If it is an image being loaded on an ImageView, you may try using the Picasso library which will handle bitmap memory on its own.
I am trying to encrypt a sqlite database that is over 2GB in size on Android. This causes the app to crash with an I/O error.
I am using the binaries for 3.1.0 available on the page at https://www.zetetic.net/sqlcipher/sqlcipher-for-android/
Is there a limit to the file size that can be used with the sqlCipher for Android.
Thanks.
[UPDATE]
The error I get is
net.sqlcipher.database.SQLiteDiskIOException: disk I/O error
with the stack trace as
[net.sqlcipher.database.SQLiteDatabase.native_setLocale(Native Method),
net.sqlcipher.database.SQLiteDatabase.setLocale(SQLiteDatabase.java:2092),
net.sqlcipher.database.SQLiteDatabase.<init>(SQLiteDatabase.java:1958),
net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:875),
net.sqlcipher.database.SQLiteDatabase.openDatabase(SQLiteDatabase.java:930),
com.puneet.android.sqlitesample.MainActivity.ConvertNormalToSQLCipheredDB(MainActivity.java:134),
com.puneet.android.sqlitesample.MainActivity.buttonEncryptionOnClick(MainActivity.java:69),
java.lang.reflect.Method.invokeNative(Native Method),
java.lang.reflect.Method.invoke(Method.java:515),
android.view.View$1.onClick(View.java:3978),
android.view.View.performClick(View.java:4654),
android.view.View$PerformClick.run(View.java:19438),
android.os.Handler.handleCallback(Handler.java:733),
android.os.Handler.dispatchMessage(Handler.java:95),
android.os.Looper.loop(Looper.java:146),
android.app.ActivityThread.main(ActivityThread.java:5602),
java.lang.reflect.Method.invokeNative(Native Method),
java.lang.reflect.Method.invoke(Method.java:515),
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283),
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099),
dalvik.system.NativeStart.main(Native Method)]
The file is 2GB in size.
I've been experimenting Shared elements transitions with Android-L preview (Nexus 7), and faced OutOfMemoryError exceptions when used with a ViewPager. But I also tried on Romain's google-io-2014 demo, and got the same problem after clicking on a picture then hitting back, a couple of times (between 10 to 15). Is it a bug in the SDK, and there's something that should be done on the application side (recycle())?
java.lang.OutOfMemoryError: Failed to allocate a 1817612 byte allocation with 772936 free bytes
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:810)
at android.graphics.Bitmap.createBitmap(Bitmap.java:787)
at android.graphics.Bitmap.createBitmap(Bitmap.java:754)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:543)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:511)
at android.app.EnterTransitionCoordinator.sendSharedElementDestination(EnterTransitionCoordinator.java:109)
at android.app.EnterTransitionCoordinator.onReceiveResult(EnterTransitionCoordinator.java:151)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:738)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
I/am_crash( 612): [17912,0,com.example.android.io2014,8961606,java.lang.OutOfMemoryError,Failed to allocate a 1817612 byte allocation with 772936 free bytes,VMRuntime.java,-2]
Update (10/17/2014): all fixed with SDK 21. Can't close the question.
Apparently this has been fixed in API 21 (according to the OP).
Note also that Romain Guy's sample project is just an example... he didn't bother writing code that properly scales down the images he uses (which is what you would normally do in a production application). If you are running the sample on a low-end device, it's possible that you might get out of memory errors. To avoid this, I recommend resizing and scaling down the drawable PNGs included in the project.