Bug 27481 - [Android] Memory leak when loading a new image into an ImageView when the previous image has not finished loading.
Summary: [Android] Memory leak when loading a new image into an ImageView when the pre...
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.1
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Eric Maupin
Depends on:
Reported: 2015-02-26 17:51 UTC by Jon Goldberger [MSFT]
Modified: 2016-04-08 19:34 UTC (History)
6 users (show)

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

Updated repro (6.46 MB, application/x-zip-compressed)
2015-06-01 19:29 UTC, Chris King

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 Jon Goldberger [MSFT] 2015-02-26 17:51:16 UTC
## Description

Memory leak and ultimate crash (after ~ 1 hour) occurs when loading images into a single ImageView in succession from a data stream of .jpg files (creating a "video" of these still images). If an image is still loading and then you try to load a new image, then there seems to be a leak. However if you check for image.IsLoading before loading a new image to make sure that the previous image was fully loaded, then there is no leak. Note that this was only noted to occur for Android. 

The above is the customer's description. My findings were a bit different. I first tested using Xamarin Android Player Nexus 4 (KitKat) simulator. On this simulator I did not get a crash whether I checked for _img.IsLoading first or not, but I only ran the app for a few minutes. But I note that the image is very choppy. On iOS simulator or device the images load much more quickly and the "animation" is much more smooth. On Android simulator, "animation" is very choppy but on my device, a Samsung Galaxy 2 Tab, the app crashed with an out of memory exception before a single image is displayed with or without checking for _img.IsLoading first. Changing the timer interval (change _lblPicker.SelectedValue on line 38 of App.cs) to 200 (instead of 100), then I do not get the out of memory exception on my device if checking for _img.IsLoading first, however out of memory crash still occurs almost instantly before the first image is even shown. 

## Steps to reproduce.

1. OPen test project and set the Android project as the startup project.

2. Launch app to a Android device (as stated, only tested on Samsung Galaxy Tab 2)

Expected result: A series of images will be displayed in quick succession.

Actual result: app crashes with an OutOfMemory exception 

## Notes

Try commenting out lines 93-94 and uncommenting lines 97-98 in App.cs to check for _img.IsLoading. With this check in place and the timer interval set to >= 200 on line 38 of App.cs, then the images do show in quick succession without an our of memory crash, well at least for as long as I let it ran which was about 10 minutes. With the check for _img.IsLoading still in place and the timer interval set to 100, the app still crashes almost instantly.

## Version info

I tested this with Forms version 1.3.1 as that was what was in the test project when I got it. But I noted the same behavior after updating to 1.3.4. Attached test project is using 1.3.4.
Comment 2 Atin 2015-03-03 11:58:09 UTC
I have checked this issue and able to reproduce this behaviour with the help of sample and steps given in the bug description. When I run the TestProject then following exception occur:

Java.Lang.OutOfMemoryError: Exception of type 'Java.Lang.OutOfMemoryError' was thrown

I have checked this issue with Xamarin.Forms:

Application Output:https://gist.github.com/sunil360/4929a5ad110a7fbdecc1
Ide Logs:https://gist.github.com/sunil360/ddf32fa520f089b5a2a6
Android Logs(adb logcat): https://gist.github.com/saurabh360/e4b2095210baff3b3a30

Device info: Samsung Galaxy Tab 2(Android 4.1.2) 

Environment Info:

=== Xamarin Studio ===

Version 5.7.2 (build 8)
Installation UUID: 0b7eaebc-a0ed-4b58-81df-91e378cad28c
	Mono 3.12.0 ((detached/b8f5055)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000077

=== Xamarin.Android ===

Version: (Enterprise Edition)
Android SDK: /Users/Admin_Mac/Desktop/Anddk/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)
		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)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: 9905782
Build date: 2015-02-26 11:05:07-0500

=== Xamarin.Mac ===

Version: (Enterprise Edition)

=== Build Information ===

Release ID: 507020008
Git revision: 64a4266f0a82f7558472383d8ae66a526b3b881d
Build date: 2015-02-25 11:22:12-05
Xamarin addins: 1cb443ca2dddd9933d748e035560f06cf9c246bd

=== Operating System ===

Mac OS X 10.10.2
Darwin Admin-Macs-Mac-mini.local 14.1.0 Darwin Kernel Version 14.1.0
    Thu Nov 13 18:36:56 PST 2014
    root:xnu-2782.10.65~2/RELEASE_X86_64 x86_64
Comment 3 Chris King 2015-06-01 19:29:11 UTC
Created attachment 11415 [details]
Updated repro

Thanks for submitting this issue. I've updated the repro a bit so that the device can now cycle through the images as fast as it can without crashing. The device can load them as fast as the CPU can handle which is less than 60 fps on my device. Were you hoping to blit them at 60 fps? Mind if I ask why you don't embed a video so you can get GPU acceleration?
Comment 4 E.Z. Hart [MSFT] 2016-04-08 19:34:02 UTC
Thank you for your bug report. As we have not received the information requested, we cannot properly triage your bug and are marking it resolved.

Warm regards,
Xamarin Forms Team