Bug 27649 - Changing the BackgroundColor of a Button many times results in a OOM exception
Summary: Changing the BackgroundColor of a Button many times results in a OOM exception
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.5
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Jason Smith [MSFT]
Depends on:
Reported: 2015-03-04 11:40 UTC by John Miller [MSFT]
Modified: 2015-05-15 16:25 UTC (History)
5 users (show)

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

Test Case (48.83 KB, application/zip)
2015-03-04 11:40 UTC, John Miller [MSFT]

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 John Miller [MSFT] 2015-03-04 11:40:04 UTC
Created attachment 10151 [details]
Test Case


   Changing the BackgroundColor of a Button many times results in an OutOfMemory exception on Android

**Steps to Reproduce:**

   1. Run the attached sample on an Android Device
   2. Toggle back and forth by touch the View A and View B buttons at the bottom
   3. Repeat step 2 ~100 times

**Actual Results:**

   An OutOfMemory exception occurs. 

**Expected Results:**

   No exception.

**Build Date & Platform:**

   XF 1.3.5
  Moto G Android 4.4 API 19
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-03-31 00:28:00 UTC
While we're waiting for further testing on other devices, if the original customer can still reliably reproduce this problem on a Moto G Android 4.4. API 19, it might be worth trying a quick (if "indelicate") test: add a `GC.Collect(); GC.WaitForPendingFinalizers();` to the event handler for `buttonViewA.Clicked` or `buttonViewB.Clicked`, or both.

In my quick initial tests (following the steps on [1] on the Xamarin Android Player (API 19)), I saw:

(a) When I added `GC.Collect(); GC.WaitForPendingFinalizers();` to both of the `Clicked` event handlers and then tapped 400 times: the heap size plateaued around 400,000, and the managed object counts plateaued around 7200 after about 150 button taps. In this experiment, the only object type that changed counts after the third button click was `System.WeakReference`.

(b) When I tapped 400 times and then explicitly called `GC.Collect()` to log the current heap: the heap size reached 2,624,704, and the managed object count reached 65149. The most numerous and most space-consuming object type on the heap was `System.WeakReference`.

> [1] http://stackoverflow.com/questions/19125266/how-to-take-heap-snapshot-of-xamarin-androids-mono-vm/19126051#19126051

- Brendan
Xamarin Customer Support
Comment 3 Jason Smith [MSFT] 2015-05-15 16:25:55 UTC
Fixed in master