Getting OutOfMemoryException in Xamarin

java.lang.OutOfMemoryError. Consider increasing the value of $ (JavaMaximumHeapSize). Java ran out of memory running 'java.exe'

I am getting a memory exception in my Visual Studio Xamarin project. Please help me how can I solve this problem.

+65
c # visual-studio xamarin xamarin.android
Apr 25 '16 at 8:48
source share
9 answers

I would increase the size of the assembly heap.

Right-click your Android project> Properties > Android Settings > Advanced > Maximum Java Heap Size .

enter image description here

+116
Apr 25 '16 at 8:54
source share

The selected answer leads me in the right direction, but for Visual Studio 2017, the screen looks like this:

VS 2017 Updated Screens

VS 2017 Updated Screens

+17
Dec 14 '17 at 17:03
source share

If you want to increase the heap size of your application (and not the build process), you can install it in your AndroidManifest.xml:

<application android:largeHeap="true"></application> 
+16
Apr 25 '16 at 9:00
source share

For Visual Studio 2015, right-click Project -> Properties -> Android Options -> Advanced and Heap Size.

+12
Jun 14 '16 at 10:48
source share

As with Xamarin studio version 6.3 and visual studio 7.0.1, the ability to increase heap size can be found here.

Right-click on the Android project, then select the options and select “Build / Android Build”, then the “Advanced” tab and set 1G (or something else) to the Java heap size

enter image description here

+3
Aug 10 '17 at 12:43 on
source share

When you run out of 1G heap size, start optimizing resources.

First, check if you are copying image instances by storing the same image in memory several times. To do this, use the ffimageloading library ( https://github.com/luberda-molinet/FFImageLoading ) to get it quickly and easily.

Then optimize the images you use. For large images other than thumbnails, try converting everything to JPEG format, avoiding png with the transparency that once saved me for constant numbers.

Then try using thumbnails instead of images if you can have large downloaded images on your remote. On your server, pre-create thumbnails for different sizes, mini, small, medium, normal, large, large, etc., and upload only those images that you really need. It saves a lot of memory and speed.

Another is memory leaks. You may have cells or other elements that are still in memory if they are not unsubscribed from messages, event handlers, and some others. Imagine that you may have several copies of a list full of images still in memory when you are sure that this will not happen. More info here:

https://forums.xamarin.com/discussion/123876/should-we-unsubscribe-all-events-for-memory-management

https://forums.xamarin.com/discussion/87206/messaging-center-unsubscribe-from-all-messages-when-broadcast-stops

+2
May 27 '18 at 8:47
source share

Increasing java max heap size works for me

enter image description here

0
Dec 19 '17 at 2:14 on
source share

I fixed the addition below to the AndroidManizest.xml application tag

 <application android:largeHeap="true" android:label="sample"></application> 
0
Apr 23 '19 at 9:37
source share

In my experience, memory problems occur ONLY in the Android version of Xamarin.Forms. And it always has to deal with oversized images. I dealt with this problem using FFImageLoading ( https://github.com/luberda-molinet/FFImageLoading )

Replace your

 <Image Source="waterfront.jpg" /> 

FROM

 <ffimageloading:CachedImage Source="waterfront.jpg" DownsampleToViewSize = true, BitmapOptimizations = true/> 

You will see a sharp improvement in performance, and it will also solve memory problems.

0
Apr 24 '19 at 17:22
source share



All Articles