Bug 35531 - Grid layout running out of memory on display
Summary: Grid layout running out of memory on display
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.5.2
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-11-04 07:47 UTC by Paul Johnson
Modified: 2017-06-17 01:36 UTC (History)
2 users (show)

Tags: android, grid
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Paul Johnson 2015-11-04 07:47:37 UTC
I have a grid layout. To construct each cell, I create an image (scaled from resources) which is then placed in a stack layout with a label under it. Once constructed, I add the grid to a scrollview with is then added to the master page content.

The app crashes while rendering with an out of memory exception.

The filenames are from Resources/drawable and passed in as a string

 void GenerateUi()
        {
            var topbar = new TopBar("", this, "icoback.png").CreateTopBar(); 

            var scroll = new ScrollView();

            var grid = new Grid
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                RowDefinitions =
                {
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = GridLength.Auto },
                    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) },
                    new RowDefinition { Height = new GridLength(100, GridUnitType.Absolute) }
                },
                ColumnDefinitions =
                {
                    new ColumnDefinition { Width = GridLength.Auto },
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) },
                    new ColumnDefinition { Width = new GridLength(100, GridUnitType.Absolute) }
                }
            };
                        
            int left = 0, top = 0;
            StackLayout sl = null;
            foreach (var pi in filenames)
            {
                var img = new Image
                {
                    Source = pi,
                    HeightRequest = 150,
                    WidthRequest = 150,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions = LayoutOptions.CenterAndExpand
                };
                sl = new StackLayout
                {
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    Orientation = StackOrientation.Vertical,
                    Padding = new Thickness(8, 8),
                    Children =
                    {
                        img,
                        new Label
                        {
                            Text = pi.Substring(0, 10)
                        }
                    }
                };
                sl.GestureRecognizers.Add(new TapGestureRecognizer
                    {
                        NumberOfTapsRequired = 1,
                        Command = new Command(async () =>
                            {
                                var page = new ProductsTabs();
                                page.SetBinding(Page.ClassIdProperty, new Binding(sl.StyleId));
                                await Navigation.PushAsync(page);
                            })
                    });

                grid.Children.Add(sl, left, top);
                left++;
                if (left == 2)
                {
                    left = 0;
                    top++;
                }
                sl = null;
            }

            scroll.Content = grid;
            Content = new StackLayout
            { 
                Orientation = StackOrientation.Vertical,
                VerticalOptions = LayoutOptions.StartAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                Children =
                {
                    new StackLayout
                    {
                        VerticalOptions = LayoutOptions.Start,
                        HorizontalOptions = LayoutOptions.Start,
                        WidthRequest = App.ScreenSize.Width,
                        Children = { topbar }
                    },
                    scroll
                }
            };
        }

I have tried a custom image which does the scaling for me (using code I've used before in a standard Xam.Android app that does all of the work within using {...} constructs with the same result.

=== Xamarin Studio ===

Version 5.10 (build 860)
Installation UUID: 728e2a5d-c6a2-4d84-a931-ee64cb78694c
Runtime:
	Mono 4.2.1 (explicit/8862921)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010091

=== Xamarin.Profiler ===

Version: 0.18.0.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 7.1 (9079)
Build 7B91b

=== Xamarin.iOS ===

Version: 9.2.1.21 (Business Edition)
Hash: 9ce9e8b
Branch: master
Build date: 2015-10-28 19:11:03-0400

=== Xamarin.Android ===

Version: 6.0.0.27 (Business Edition)
Android SDK: /Users/PFJ/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.3.7
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.4.0.105 (Starter Edition)

=== Build Information ===

Release ID: 510000860
Git revision: 7c46a0b709d51ad5d5a5ed90a4671cc7b6928e62
Build date: 2015-10-29 17:17:52-04
Xamarin addins: b9337905aca5dc276190d78819728a59cda33a43
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.11.1
Darwin Pauls-MacBook-Pro.local 15.0.0 Darwin Kernel Version 15.0.0
    Sat Sep 19 15:53:46 PDT 2015
    root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64

I'm using the current alpha version of Xam.Forms (1.5.2.6469-pre1). The code works fine with iOS
Comment 1 Jason Smith [MSFT] 2016-04-13 19:46:25 UTC
Can you please provide the device and images you are using?
Comment 2 Paul Johnson 2016-04-13 21:24:15 UTC
It was tested on the emulator as well as a Cubot X12. Images - https://www.dropbox.com/sh/g3vqcxg5o7uy6m9/AAAi28HzSzARHVxKUqL5ilbKa?dl=0
Comment 3 David Ortinau [MSFT] 2017-06-17 01:36:45 UTC
I'm not able to reproduce this issue on 2.3.5. If this issue is still occurring for you, please reopen it and provide a project that demonstrates this issue.