Getting OutOfMemoryException in Xamarin

2019-01-14 00:04发布

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

I am getting out of memory exception in my visualstudio Xamarin Project Please help me how can i resolve this issue.

7条回答
放我归山
2楼-- · 2019-01-14 00:06

If you want to increase Heap size of your application (not the build process) you can set this in your AndroidManifest.xml:

<application android:largeHeap="true"></application>
查看更多
该账号已被封号
3楼-- · 2019-01-14 00:09

For visual studio 2015 right click Project --> Properties --> Android Options --> Advanced and heap size there.

查看更多
姐就是有狂的资本
4楼-- · 2019-01-14 00:18

I would increase your build heap size.

Right click your Android Project > Properties > Android Options > Advanced > Java Max Heap Size.

enter image description here

查看更多
Melony?
5楼-- · 2019-01-14 00:18

Increasing java max heap size works for me

enter image description here

查看更多
放我归山
6楼-- · 2019-01-14 00:22

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

VS 2017 Updated Screens

VS 2017 Updated Screens

查看更多
来,给爷笑一个
7楼-- · 2019-01-14 00:26

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

First check if you are not duplicating images instances, keeping same image in memory several times. For that use ffimageloading library (https://github.com/luberda-molinet/FFImageLoading) get it on nuget fast and easy.

Then optimize images you are using. For large images, other than icons, try converting everything to jpeg avoiding png with transparency, that once saved me for constant ooms.

Then try using thumbnails instead of images when you might have large uploaded images on remote. On your server pre-create thumbnails for different sizes, mini, small, medium, normal , large, xlarge etc, and load only images of size you really need. That saves a lot of memory and speed.

Another one is memory leaks. You might have cells or other elements still reside im memory if they didn't unsubscribe from messages, eventhandlers and some other. Imagine you could have several copies of a list full of images still in memory when you are sure that couldn't 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

查看更多
登录 后发表回答