Bug 56052 - Activities Not Being Garbage Collected
Summary: Activities Not Being Garbage Collected
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
Depends on:
Reported: 2017-05-05 16:36 UTC by Cory Juhlin
Modified: 2017-06-29 21:43 UTC (History)
2 users (show)

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

Sample project (10.14 KB, application/zip)
2017-05-05 16:36 UTC, Cory Juhlin
Profiler at beginning of session (130.63 KB, image/png)
2017-06-29 21:41 UTC, Mark McLemore
Profiler after 7 rotation cycles (136.19 KB, image/png)
2017-06-29 21:42 UTC, Mark McLemore

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.

* Xamarin Profiler 1.4.0-1
* Xamarin Studio 6.3
* Xamarin.Android (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 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).

Note You need to log in before you can comment on or make changes to this bug.