I have very tired with getting java lang out of memory exception in xamarin android project. I didn't find what the root cause of getting this exception. In my android properties set up heap size is '1G' but still getting same issue.I am not getting any issue while xamarin ios project set as starting project.So many post's are suggest to these following solutions 1. increase heap size 2.set large hepad size is true in android manifest file, I am fallow those solutions but getting same issue. Here is the error what I am getting. Please suggest any idea of how to fix this issue.

-
What's in the Show Details bit? Is it perhaps trying to allocate a bunch of memory for an image? If you are loading a lot of images on Android, that could be your root cause.Ewald– Ewald2017-09-07 08:56:29 +00:00Commented Sep 7, 2017 at 8:56
-
How can we load lot of images in xamarin forms. Is there any alternative solution. In ios it working in nice, only in android getting this type of issue.Deepak– Deepak2017-09-07 13:39:27 +00:00Commented Sep 7, 2017 at 13:39
-
Ok, so the problem IS loading images. It's probably because the images are way to big for Android compared to iOS. Are you using the correct image sizes for each screen size that you need to support?Ewald– Ewald2017-09-07 14:03:36 +00:00Commented Sep 7, 2017 at 14:03
-
I am using image height 100 and width is 130 for android. These sizes are fine for android.Deepak– Deepak2017-09-07 14:19:25 +00:00Commented Sep 7, 2017 at 14:19
-
Kindly show us what's in the Show Details section of the exception.Ewald– Ewald2017-09-07 15:07:46 +00:00Commented Sep 7, 2017 at 15:07
3 Answers
Just like you did with the PATH stuff in the other thread, add that to the export _JAVA_OPTIONS="-Xmx1g" to the mix, restart Visual Studio and see if that helps.
If you are still running into issues with with the build failing with an OutOfMemoryException you can try upgrading your JDK to use x64 instead of x86. The x64 JDK handles the larger Heap Size better than the x86 JDK.
Another problem is that maybe you have installed two versions of JDK tries to uninstall one and stay with the most current or that supports 64 bits.
Comments
I ran into this issue building my android project and @G.hakim's suggestion worked perfectly for me. Thanks for that @G.hakim! For those Building in Visual Studio on Mac,
- Open The MainApplication.cs file in your Droid Folder
Add the following line before the
public class MainApplication:...declaration[Application(HardwareAccelerated = true, LargeHeap = true)]
Thats it! You can also implement the FFImageLoading package, if your app is image heavy.