1

How can I enable large heap in my Xamarin.Forms application ?

Here is MainActivity.cs Android code:

 public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);
        global::Xamarin.Forms.Forms.Init(this, bundle);
        RoundedBoxViewRenderer.Init();
        LoadApplication(new App());
    }
}

See Exception Screenshot below:

Exception Screenshot

3 Answers 3

1

Go to project Options > Android Build > General > Enable MultiDex & Options > Android Build > Advacnced > JavaHeapSize (Set 3G) , In manifest file you can add android:largeHeap="true" in Application Tag

<application android:largeHeap="true"/>
Sign up to request clarification or add additional context in comments.

6 Comments

how can i get these option in VS2013
Go to Solution Explorer , Right Click on the Android Project eg. MyProject.Droid in Popup select Properties/Option then follow the above
Before you enable largeHeap you should try to find out what causes the OutOfMemoryException and fix that. In most if not all cases are memory leaks the root of all that eval. Go use the Xamarin Profiler and Android Studios memory monitor to profile your apps memory usage.
we have set heapsize to 3G , but unable to find manifest file for add tag. where is it ? - imrohit
We have got the manifest file and added tag as you type above, OutOfMemoryException still there its crashes the app when we load images from URLs.
|
1

The Xamarin way of setting the Dalvik/Art large heap via the Appication attribute:

Application.cs

using System;
using Android.App;
using Android.Runtime;

namespace LargeHeap
{
    [Application(LargeHeap = true)]
    public class XamarinApplication : Application
    {
        public XamarinApplication(IntPtr handle, JniHandleOwnership ownerShip) : base(handle, ownerShip)
        {
        }
    }
}

If true, then the process should be created with a large Dalvik heap; otherwise, the process will be created with the default Dalvik heap.

Ref: https://developer.xamarin.com/api/property/Android.App.ApplicationAttribute.LargeHeap/

Comments

0

My contribution, it worked for me:

[assembly: Application(LargeHeap = true)]

namespace Project.Droid
{
    [Activity(.............)]

    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {

    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.