Bug 56052 - Activities Not Being Garbage Collected
Summary: Activities Not Being Garbage Collected
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 7.2 (15.1)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2017-05-05 16:36 UTC by Cory Juhlin
Modified: 2017-06-29 21:43 UTC (History)
2 users (show)

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


Attachments
Sample project (10.14 KB, application/zip)
2017-05-05 16:36 UTC, Cory Juhlin
Details
Profiler at beginning of session (130.63 KB, image/png)
2017-06-29 21:41 UTC, Mark McLemore
Details
Profiler after 7 rotation cycles (136.19 KB, image/png)
2017-06-29 21:42 UTC, Mark McLemore
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 for Bug 56052 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Cory Juhlin 2017-05-05 16:36:57 UTC
Created attachment 21982 [details]
Sample project

According to Xamarin Profiler, Android Activities are not being garbage collected when device is rotated multiple times.

I am using Xamarin Profiler on a simple sample project that has a call to `GC.Collect()` in the main Activity's `OnCreate` method. After rotating the device multiple times, inspecting a snapshot reveals more than one instance of the Activity is marked as 'Live' in the Profiler. I assume 'Live' means that the object is unable to be garbage collected.

I can observe this whether or not the "Don't Keep Activities" setting in the Android developer options is enabled.

Using:
* Xamarin Profiler 1.4.0-1
* Xamarin Studio 6.3
* Xamarin.Android 7.2.0.7 (VS Enterprise)
* macOS 10.12.4
* Android Emulator with Nexus 5 configuration running Android 7.1.1

Maybe I am not understanding the intended behavior, but from what I understand about how the Mono VM GC works on Android, these Activities should be destroyed by the call to `GC.Collect()` or even the snapshot feature in the profiler.
Comment 1 Mark McLemore 2017-06-29 21:41:38 UTC
Created attachment 23227 [details]
Profiler at beginning of session
Comment 2 Mark McLemore 2017-06-29 21:42:45 UTC
Created attachment 23228 [details]
Profiler after 7 rotation cycles
Comment 3 Mark McLemore 2017-06-29 21:43:13 UTC
Confirmed via Visual Studio 2017 Enterprise and Xamarin.Android 7.3.1.2 on Windows.

The before.png screenshot shows the beginning of the profiler session. Note that Andleaks.MainActivity count is 1. After 7 rotation cycles (Nexus 5), the Andleaks.MainActivity count goes to 15 (see after.png).