Bug 22510 - Out of memory on Android with listview having an image in it
Summary: Out of memory on Android with listview having an image in it
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.2.2
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-29 11:11 UTC by Devin Rose
Modified: 2015-11-09 11:09 UTC (History)
12 users (show)

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


Attachments
gradient image used in the code example (2.65 KB, image/png)
2014-08-29 11:12 UTC, Devin Rose
Details
solution and projects to use to reproduce (25.95 KB, application/zip)
2014-08-29 13:11 UTC, Devin Rose
Details


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:
VERIFIED FIXED

Description Devin Rose 2014-08-29 11:11:56 UTC
I have discovered that Android can run out of memory quite quickly with a listview that has an image in its itemtemplate, if that image has a large width and height.

The file size of the image does not matter, just the width/height of it. My image is a 1280x337, 3KB png, and with just five to ten items in my listview, it will crash when you scroll it.

public OtherPage ()
    {
        Title = "Other Page";

        BackgroundColor = Color.White;

        var settings = new ListView ();
        settings.RowHeight = 120;

        List<string> items = new List<string> ();
        for (int i = 0; i < 8; i++) {
            items.Add ("Item " + i);
        }
        settings.ItemsSource = items;

        settings.ItemTemplate = new DataTemplate (() => {

            Image gradientOverlay = new Image()
            {
                Source = "colorgradient.png",
                Aspect = Aspect.Fill
            };

            Grid screenGrid = new Grid () {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                RowDefinitions = 
                {
                    new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }
                },
                ColumnDefinitions = 
                {
                    new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }
                }
                };

            screenGrid.Children.Add(gradientOverlay, 0, 0);

            return new ViewCell { 
                View = screenGrid,
            };
        });

        Content = settings;

    }
Comment 1 Devin Rose 2014-08-29 11:12:29 UTC
Created attachment 7871 [details]
gradient image used in the code example
Comment 2 Devin Rose 2014-08-29 11:13:25 UTC
Note that if I replace this image by another png that is 3 KB but whose width height are much smaller, I do not hit out of memory. Also, iOS handles this fine for the same Xamarin Forms shared code/app.
Comment 3 Devin Rose 2014-08-29 13:11:09 UTC
For me it crashes on my Samsung Galaxy S5. Attaching the xamarin solution and projects.
Comment 4 Devin Rose 2014-08-29 13:11:40 UTC
Created attachment 7873 [details]
solution and projects to use to reproduce
Comment 5 Rajneesh Kumar 2014-09-01 04:42:13 UTC
I have checked this issue and able to reproduce. To reproduce this issue I I have followed the instruction, sample code mentioned in the bug description. I observed that in the attached sample application, If the image size is 1280x337 in listview  template, I am getting the "Out of memory on a 15528976-byte allocation", in application output window,and "Java.Lang.OutOfMemoryError" exception is thrown. I also observed that If i reduce the image size to (Eg: 1058x305), the application is running successfully, without any error.

Note: I observed that  in this issue the image file size does't matter, only height and width affect this.


Screencast: http://www.screencast.com/t/Fi1m6zPNv5H
Exception : https://gist.github.com/Rajneesh360Logica/8620174a57bd0c6c44a9

Environment Info:

=== Xamarin Studio ===

Version 5.2 (build 386)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 3.8.0 ((detached/356dbc5)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308109010

=== Xamarin.Android ===

Version: 4.14.0 (Enterprise Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		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)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Apple Developer Tools ===

Xcode 6.0 (6256.16)
Build 6A280e

=== Xamarin.iOS ===

Version: 7.2.6.28 (Enterprise Edition)
Hash: 606f31a
Branch: 
Build date: 2014-08-01 15:27:48-0400

=== Xamarin.Mac ===

Version: 1.11.0.1 (Enterprise Edition)

=== Build Information ===

Release ID: 502000386
Git revision: e6a54dee5376e6e7a2d9982695b060fddc09e65d
Build date: 2014-08-04 14:03:28-04
Xamarin addins: 2b5a5c26ac2ee74c6e91a8d24ef44d0ca9cb74d0

=== Operating System ===

Mac OS X 10.9.4
Darwin MacMini.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 6 Jonathan Pryor 2014-09-02 10:05:51 UTC
Note: the file size of the image is largely irrelevant, on all platforms, as the image needs to be "decompressed" into a screen-optimal format in order to be displayed on screen. This screen-optimal is frequently 4-byte-per-pixel ARGB.

Consequently, even if your 1280x337 image is 3KB, it *actually* requires 1280*337*4 = 1,725,440b = 1.7MB per image, just to show the image on the screen.
Comment 7 Erik Renaud 2015-03-08 23:09:03 UTC
I am having this same problem - any news ?
Comment 8 Jason Smith [MSFT] 2015-05-26 23:46:08 UTC
I can not reproduce this issue in the latest pre-release, can you please confirm you still see it?
Comment 9 Rajneesh Kumar 2015-05-27 06:21:13 UTC
I have checked this issue issue with the Xamarin.Forms Version: 1.4.3.6358-pre2 and observed that this issue does't exist with this version of forms. Now I am able to build and deploy the attached test sample without any error of exception in application output.

Screencast: http://www.screencast.com/t/yKHvtUnI

This issue seems fixed, because I am not reproducible now, so as of now I am closing this issue this issue if anybody still face this issue so feel free to reopen it.

Thanks..!
Comment 10 Mac Moukalled 2015-07-07 18:42:50 UTC
I updated Xamarin to version 1.4.3.6374 and now i am having the same issue; was this issue re-introduced in this release?

I have a list view in a tabbedpage and loads it with images and text, no issue when loaded with small images (320x320), but as soon as i add lager images taking from my samsung tablet my application crashes at the 3rd reload. This is frustrating, as i was about to release my app after lengthy development and extensive testing with no issues until i upgraded Xamarin.
Comment 11 Ankur 2015-07-08 04:45:11 UTC
This bug is marked as fixed and it may take time before your comments are responded by some one from Xamarin. 
Check this out: https://bugzilla.xamarin.com/show_bug.cgi?id=29210
This bug took a lot of time to be fixed. I suggest you open a new bug and add reference for this bug in that. So, that atleast hopefully they will triage it sooner. 

Also, for now, perhaps you can try downgrading to a previous Xamarin.forms. This might also help them in nailing the exact version which caused it and getting it resolved sooner.

I too had avoided upgrading to the latest Xamarin.Forms because of the issue in the other bug I added link to. It finally got resolved and I update so that I can use Pull to Refresh feature, and now this... Now I won't be able to downgrade also!!!
Comment 12 Alessandro 2015-11-09 11:09:52 UTC
I am using 1.5.1 and I have this problem with list view and images


could be the same problem??

at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () <0x00028>
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>m__0 (object) <0x0003f>
at Android.App.SyncContext/<Post>c__AnonStorey0.<>m__0 () <0x00027>
at Java.Lang.Thread/RunnableImplementor.Run () <0x0003f>
at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) <0x0003b>
at (wrapper dynamic-method) object.b49ee73e-d2e1-4d87-89ba-f534f44bf877 (intptr,intptr) <0x0003b>

  --- End of managed exception stack trace ---
java.lang.OutOfMemoryError
	at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
	at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
	at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
	at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:445)
	at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:475)
	at dalvik.system.NativeStart.run(Native Method)