Bug 23959 - Android Lolipop - outstanding GREFs loop - causes lag + crashes
Summary: Android Lolipop - outstanding GREFs loop - causes lag + crashes
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.18.0
Hardware: PC Windows
: Normal normal
Target Milestone: 4.20
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-10-21 11:33 UTC by Craig
Modified: 2014-11-12 01:26 UTC (History)
4 users (show)

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


Attachments
Sample app for reproducing the bug (58 bytes, text/plain)
2014-10-24 14:59 UTC, Craig
Details
Logcat.txt (436.41 KB, text/plain)
2014-11-04 23:44 UTC, Rajneesh Kumar
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 Craig 2014-10-21 11:33:46 UTC
When testing my apps on the finalized release of Android Lolipop (API Level 21) in the emulator the screens load very slowly and the app crashes frequently.

Looking in the logcat output, the cause appears to a constant loop of outstanding GREFs, which causes Xamarin to repeatedly perform full Garbage Collection over and over again.

I tested the same app against the API Level 17 emulator and did NOT observe the same problems, so the problem seems to be due to either Android Lolipop or the ART runtime.  Please investigate and correct the issue.

10-17 12:22:00.603 I/monodroid-gc( 2183): 6443 outstanding GREFs. Performing a full GC!
10-17 12:22:00.651 I/monodroid-gc( 2183): 6444 outstanding GREFs. Performing a full GC!
10-17 12:22:00.712 I/monodroid-gc( 2183): 6445 outstanding GREFs. Performing a full GC!
10-17 12:22:00.771 I/monodroid-gc( 2183): 6446 outstanding GREFs. Performing a full GC!
10-17 12:22:00.839 I/monodroid-gc( 2183): 6447 outstanding GREFs. Performing a full GC!
10-17 12:22:00.889 I/monodroid-gc( 2183): 6448 outstanding GREFs. Performing a full GC!
10-17 12:22:00.943 I/monodroid-gc( 2183): 6449 outstanding GREFs. Performing a full GC!
10-17 12:22:01.020 I/monodroid-gc( 2183): 6450 outstanding GREFs. Performing a full GC!
10-17 12:22:01.082 I/monodroid-gc( 2183): 6451 outstanding GREFs. Performing a full GC!
10-17 12:22:01.144 I/monodroid-gc( 2183): 6452 outstanding GREFs. Performing a full GC!
10-17 12:22:01.219 I/monodroid-gc( 2183): 6453 outstanding GREFs. Performing a full GC!
10-17 12:22:01.277 I/monodroid-gc( 2183): 6454 outstanding GREFs. Performing a full GC!

I also created a forum post about this issue: http://forums.xamarin.com/discussion/26250/android-l-outstanding-gref-loop#latest

Thanks.
Comment 1 Rajneesh Kumar 2014-10-22 06:42:33 UTC
I try to reproduce this issue but unable to reproduce. I my case I have created a simple android application.

Steps I followed:

1. Create an android application in XS
2. Build and run it on API Label 21 emulator
3. Observed that it deploy successfully.

We observed that we are able to deploy it on API Label 21 emulator. Could you please provide us a small sample application, steps to reproduce,
environment info ? That will be very helpful to reproduce this issue at our
end.

Please let me know if I am missing anything.

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

=== Xamarin Studio ===

Version 5.5.2 (build 0)
Installation UUID: a7e29e93-6348-4126-9ebc-b2777c96a552
Runtime:
	Microsoft .NET 4.0.30319.18408
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.18.0 (Business Edition)
Android SDK: E:\android-sdk
	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.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode)

=== Build Information ===

Release ID: 505020000
Git revision: a5887be38215a6cdd3f349e102ef82a1c4f950a4
Build date: 2014-10-14 12:21:34-04
Xamarin addins: 069ddd29bb70a42238142eee9bac21a5e4b2f9f9

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 2 Craig 2014-10-23 11:24:13 UTC
It seems difficult to reproduce on a simple application.  The application I'm able to reproduce it on is using ActionBarSherlock and fragements with backstack.

I haven't been able to create a simple sample application that reproduces the issue.  It seems the larger / more complex the application the quicker the gref issue appears with no screen rotation required.  On smaller simpler applications you may have to rotate screen a lot before it appears, upwards of 30 times, but it does eventually appear.  I'd say try creating a simple application using ActionBarSherlock, making use of fragments, and then try rotating screen till you observe bug.  Sorry that is the best I can give you right now, I will try to look into it more as time allows but I need to move on to something else.

My environment info is Windows 7, Visual Studio 2013, latest android tools/sdks, running Xamarin Android 4.16 (cannot go to latest version due to unresolved bug with 9 patch images)
Comment 3 Craig 2014-10-23 11:29:23 UTC
.
Comment 4 Craig 2014-10-24 14:59:19 UTC
Created attachment 8502 [details]
Sample app for reproducing the bug

This program reproduces the bug by purposely triggering garbage collection.

Since the views are being removed each time the button is clicked you would expect them to be garbage collected, but there seems to be a leak because the number of GREFs continues to increase as you click the button each time.

Click the button about approximately 4 to 5 times while running on API Level 21 emulator and you should see the app freeze up and become unresponsive.  If you examine the logcat you should that Garbage collection is continuously happening over and over again which appears to be the cause of the app being unresponsive.

Disclaimer: My actual production program which is experiencing this bug doesn't actually loop and add views to a ViewGroup like this.  It uses ListViews in place of this type of code.  However it is still triggering garbage collection and experiencing the same bug.
Comment 5 Craig 2014-10-24 15:00:17 UTC
I've added an attachment, click the button repeatedly until you experience the bug (usually about 4 - 5 times, but may take longer depending on your emulator settings).  Thanks.
Comment 6 Craig 2014-11-03 10:42:09 UTC
Can you please look at the updated information and let me know the status of this bug ticket?  Please let me know if you are able to confirm the bug.  Thanks.
Comment 7 Rajneesh Kumar 2014-11-04 00:56:45 UTC
I have checked this issue and able to reproduce this issue. To reproduce this issue I have followed the steps mentioned below:

1. Open attached sample provided in comment 4.
2. Build the application it will build successfully.
3. Deploy it on API 21 emulator, observe it will deploy.
4. Click the button repeatedly 4-5 times.

I observed that in the emulator the screens load very slowly and the app crashes frequently. Looking in the application output, the cause appears to a constant loop of outstanding GREFs, which causes Xamarin to repeatedly perform full Garbage Collection over and over again.In actual what is going on, please refer the screencast.

App O/P: https://gist.github.com/Rajneesh360Logica/9b0618f5deabe7af65dd

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

Environment Info:

=== Xamarin Studio ===

Version 5.5.3 (build 6)
Installation UUID: a7e29e93-6348-4126-9ebc-b2777c96a552
Runtime:
	Microsoft .NET 4.0.30319.18408
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.18.1 (Business Edition)
Android SDK: E:\android-sdk
	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.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) Client VM (build 20.14-b01, mixed mode)

=== Build Information ===

Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:11:11-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6

=== Operating System ===

Windows 6.2.9200.0 (64-bit)
Comment 8 Jonathan Pryor 2014-11-04 22:55:59 UTC
Could you please enable GREF logging, run your test, and attach the logcat output?

    $ adb shell setprop debug.mono.log gref
    $ adb logcat > logcat.txt
    # run your app...
    [Ctrl+C]
    # attach logcat.txt
Comment 9 Rajneesh Kumar 2014-11-04 23:44:09 UTC
Created attachment 8626 [details]
Logcat.txt

@Jonathan Pryor Thanks.

Here are the logcat as per your instruction, provided in comment 8.
Comment 10 T.J. Purtell 2014-11-09 13:51:01 UTC
Android Lollipop changed System.gc() so it no longer explicitly GCs in many cases.  Instead, Runtime.getRuntime().gc() is required.

I think the bridge processing needs to be updated to reflect this.  

This issue is very likely the same bug as https://bugzilla.xamarin.com/show_bug.cgi?id=24268
Comment 11 Craig 2014-11-10 15:09:33 UTC
Thanks for your time researching this T.J.

Xamarin can you please provide an update?  Thanks.
Comment 12 Jonathan Pryor 2014-11-11 15:58:40 UTC
T.J.: THANK YOU THANK YOU THANK YOU.

Fixed in monodroid/42fb5811 and monodroid-4.20-series/812ca135.

This should be included in the forthcoming Xamarin.Android 4.20 beta.
Comment 13 Rajneesh Kumar 2014-11-12 01:26:42 UTC
I have checked this issue with the following builds:

Xamarin Studio : 5.5.3 (build 6)
Xamarin.Android: 4.20.0 (Business Edition)
GTK# Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:11:11-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6
Operating System: Windows 6.2.9200.0 (64-bit)

I observed that the application is running without crashes on emulator and looking into the application output, Not getting constant loop of outstanding GREFs.

Hence closing this issue.

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

App O/P: https://gist.github.com/Rajneesh360Logica/ecce286f0433556b067e