1

So, i have some problems with my Xamarin.Forms app. I am getting "Java.Lang.OutOfMemoryError" when I am trying to await ViewExtensions.LayoutTo.

I have tried to increase Java Heap size up to 2G, but it did not help.

public class SplashPage : ContentPage
    {
    public SplashPage()
        {
            NavigationPage.SetHasNavigationBar(this, false);

            AbsoluteLayout layout = new AbsoluteLayout();
            Content = layout;

            Image image1 = new Image
            {
                Source = ImageSource.FromFile("image1.png"),
            };
            layout.Children.Add(image1);

            Image image2 = new Image
            {
                Source = ImageSource.FromFile("image2.png"),
            };
            layout.Children.Add(image2);

            Image image3 = new Image
            {
                Source = ImageSource.FromFile("image3.png"),
                Scale = 0.5,
            };
            layout.Children.Add(image3);

            layout.SizeChanged += async (s, e) =>
            {
                AbsoluteLayout.SetLayoutBounds(image1, new Rectangle(0, 0, image1.Width, image1.Height));
                AbsoluteLayout.SetLayoutBounds(image2, new Rectangle(0, ((AbsoluteLayout)s).Height, image2.Width, image2.Height));
                AbsoluteLayout.SetLayoutBounds(image3, new Rectangle(-image3.Width, ((AbsoluteLayout)s).Height - image3.Height - 5, image3.Width, image3.Height));

                // I have placed those animations in SizeChanged event because i needed to get actual size of layout (outside this event it would be incorrect)
                await ViewExtensions.LayoutTo(image2, new Rectangle(0, ((AbsoluteLayout)s).Height - image2.Height, image2.Width, image2.Height), 2300);
        // here Java.Lang.OutOfMemoryError
                await ViewExtensions.LayoutTo(image3, new Rectangle(((AbsoluteLayout)s).Width, ((AbsoluteLayout)s).Height - image3.Height - 5, image3.Width, image3.Height), 3000);

                await Task.WhenAll(
                    image2.FadeTo(0, 700), image1.FadeTo(0, 700));

                Application.Current.MainPage = new NavigationPage(new LoginPage());
            };
        }
    }
mxxyyy
  • 11
  • 1
  • Do you mean when you run this code you get the OutOfMemoryError? I test the code without errors. Could you provide more information for me to reproduce? Code sample would be helpful. – Wendy Zang - MSFT Oct 25 '19 at 06:50

1 Answers1

1

Try this way to increase your app's heap size in your AndroidManifest.xml:

<application android:largeHeap="true"></application>
zpouip
  • 787
  • 5
  • 11
  • Also, I would not recommend to set Java Heap size to 2G, I would go with 1G. In other cases, maybe think about optimizing app esources. – zpouip Oct 24 '19 at 14:00