Reputation: 13
What is the issue which will cause the app crash when a user opens the app?
I integrate with HockeyApp, the error shown:
VMRuntime.newNonMovableArray java.lang.OutOfMemoryError: Failed to allocate a 63701004 byte allocation with 16777056 free bytes and 41MB until OOM
Xamarin caused by: java.lang.OutOfMemoryError: Failed to allocate a 63701004 byte
allocation with 16777056 free bytes and 41MB until OOM
dalvik.system.VMRuntime.newNonMovableArray(Native Method)
android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
android.graphics.BitmapFactory.decodeStreamInternal()BitmapFactory.java:639
android.graphics.BitmapFactory.decodeStream()BitmapFactory.java:615
android.graphics.BitmapFactory.decodeStream()BitmapFactory.java:653
Answer I already solve the problems with
Upvotes: 1
Views: 1576
Reputation: 6795
I had the same issue. It turned out that multiple changes solved the problem.
Firstly, I ensured that my app can deal with large memory heaps. This is a setting you can set/change in the app's manifest:
<application
...
android:largeHeap="true"> <!-- This line does the trick. -->
Secondly, I made sure that I enforce small image sizes wherever possible. In my case I decided to limit the max resolution to either 720 pixels or the screen resolution, whatever is smaller. As a result I resized large images:
int maxImageSideLength = Math.Min(720, Math.Max(myScreenHeight, myScreenWidth));
// see tutorials how to resize the image now
Lastly, I ensured to dispose image bitmaps (used memory) that where assigned to image views before I assigned a new image. I am uncertain whether this is really necessary as I can't believe that assigning a new image bitmap isn't cleaned up properly, but I left this in my code and I am still happy with a smoothly running app. Example:
Bitmap resizedImage = ResizeImage(fileName, maxImageSideLength);
imageView.SetImageBitmap(null); // this is to free allocated memory
imageView.SetImageBitmap(resizedImage);
GC.Collect(); // dispose of the Java side bitmap
Upvotes: 0
Reputation: 16793
Add in your manifest these lines android:hardwareAccelerated="false"
, android:largeHeap="true"
it may solve your issue(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">
Upvotes: 2