0

I develop an android application, in c#, using xamarin. It uses a lot of memory. For long time, I used weaker 2GB device to run it successfully. Now I changed phone for 4GB device and suddenly I get out of memory exception. It's caused by creating larger bitmaps.

Here you can see output:

(13022): Starting a blocking GC Alloc
(13022): Clamp target GC heap from 271MB to 256MB
(13022): Alloc concurrent mark sweep GC freed 4(96B) AllocSpace objects, 0(0B) LOS objects, 0% free, 255MB/256MB, paused 172us total 13.525ms
(13022): Forcing collection of SoftReferences for 833KB allocation
(13022): Starting a blocking GC Alloc
(13022): Clamp target GC heap from 271MB to 256MB
(13022): Alloc concurrent mark sweep GC freed 5(120B) AllocSpace objects, 0(0B) LOS objects, 0% free, 255MB/256MB, paused 175us total 13.474ms
(13022): Out of memory: Heap Size=256MB, Allocated=255MB, Capacity=256MB

I tried all possible combinations of setting Java Max Heap Size = 1G and writing to manifest android:largeHeap="true" as was recommended here but it is still saying I'm only on 256MB, crashing at the same point. Any ideas why I don't get more heap memory? There is a lot of free memory in the system. When the time comes, I will do some optimizations, but at the moment I want to use full capabilities of my testing device to code easy way. I looked at various articles, questions and one of two highlighted actions always solved the problem. I have no idea what condition is wrong in my code.

Edit:

here is whole manifest file

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AlienChessAndroid.AlienChessAndroid" android:versionCode="1" android:versionName="1.0" android:largeHeap="true" android:installLocation="auto">
<uses-sdk android:minSdkVersion="23" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="Alien Chess" android:icon="@drawable/Alien">
</application>
</manifest>
hoacin
  • 340
  • 1
  • 2
  • 19
  • It's wired if your app works fine on 2GB device but not on 4GB device, and `android:largeHeap="true"` doesn't work for your issue? Can you please show code of your manifest? – Grace Feng Sep 06 '17 at 05:36
  • @GraceFeng-MSFT I edited the question with manifest file. I have quite some bitmaps I'm drawing into in my app and the display growed from HD to Quad HD, so this is the reason for more memory usage. – hoacin Sep 06 '17 at 06:09

1 Answers1

1

The attribute android:largeHeap="true" belongs to the application tag, please check the official document here: application. You put this attribute in manifest tag, this should be the reason why android:largeHeap="true" doesn't work for your app.

By the way, maybe it's off topic, since your problem is caused by large bitmap, using native memory (NDK & JNI) can actually bypass the heap size limitation. You can check this case: JNI bitmap operations , for helping to avoid OOM when using large images.

Grace Feng
  • 16,564
  • 2
  • 22
  • 45
  • That solved the problem. I think I will later remove all these large app-lifetime resources out from the heap, your link seems like great place where to start. Thank you! – hoacin Sep 06 '17 at 07:36