Bug 31751 - Xamarin Forms - Out of memory on Android with listview having large image in it
Summary: Xamarin Forms - Out of memory on Android with listview having large image in it
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-07-08 11:47 UTC by Mac Moukalled
Modified: 2017-08-30 12:32 UTC (History)
8 users (show)

Tags: ac, android, listview, memory
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:

Description Mac Moukalled 2015-07-08 11:47:15 UTC
I updated Xamarin to version and now i am having the same issue as:


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 larger 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 1 Chris King 2015-07-08 19:05:23 UTC
I not able to reproduce this on my Google Nexus 5 on 6374 or the latest master branch. Is there a specific device you're using?
Comment 5 Mac Moukalled 2015-07-14 12:38:30 UTC
Any Suggestions? Any Comments? Any one is checking this one out?
Comment 6 Amalia 2015-07-17 11:44:47 UTC
I have been able to reproduce this issue on a Galaxy Nexus and an HTC One M9. I've also tested on Forms

### Steps to reproduce

1) Download sample app provided in private comment 3

2) Run the app on a real device

3) Add images by clicking the '+' button in the lower left corner of the app (3 or 4 images is enough)

### Expected results

Images are added successfully

### Actual results

After third or fourth picture is added to the same category, I get an OutOfMemory exception (full error messages here: https://gist.github.com/amaliasafer/702b27c92bc17f943647)

### Additional information

=== Xamarin Studio ===

Version 5.9.4 (build 5)
Installation UUID: 1f52eea2-a387-4a2c-96c1-4637c8f8567a
	Mono 4.0.2 ((detached/c99aa0c)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400020005

=== Apple Developer Tools ===

Xcode 7.0 (8163.8)
Build 7A152u

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/amalias/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
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: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 8b265d6
Branch: master
Build date: 2015-06-30 15:19:13-0400

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 509040005
Git revision: 8010a90f6e246b32364e3fb46ef2c9d1be9c9a2b
Build date: 2015-06-08 16:52:06-04
Xamarin addins: 7e93e9c3503f28770f23ce1b7eafd829919f18e8

=== Operating System ===

Mac OS X 10.10.3
Darwin amalias.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 9 Alessandro 2015-11-09 11:11:11 UTC
I have this problem in a list view with images on 1.5.1

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 ---
	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)
Comment 10 adrianknight89 2016-11-28 06:00:33 UTC
Can anyone post a public repro?
Comment 11 David Ortinau [MSFT] 2017-08-30 12:32:06 UTC
From a previous private comment. Closing this issue.

The reason for this crash is not a bug in Xamarin.Forms, but rather how Android handles images and scaling through the BitmapFactory. You can see in the sample from comment #3 that the images are not scaled and only live in the drawable folder. There should be corresponding images in the other drawable folders (drawable-hdpi, drawable-xhdpi and drawable-xxhdpi folders. ).

Android recommends that the images are scaled and loaded into the correct size of the UI component. The easiest way to have the Android operating system handle this for you is to provide the appropriate sized images to the drawable, drawable-hdpi, drawable-xhdpi and drawable-xxhdpi folders. 

This is covered in the Google Android documentation:

Supporting Multiple Screens:
Loading Large Bitmaps Efficiently: