Bug 11922 - AndroidGameView leaks memory
Summary: AndroidGameView leaks memory
Status: RESOLVED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler ()
Version: 4.4.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2013-04-23 17:14 UTC by randyficker
Modified: 2013-04-26 09:03 UTC (History)
2 users (show)

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


Attachments
Repro code (3.34 KB, text/plain)
2013-04-23 17:14 UTC, randyficker
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:
RESOLVED FIXED

Description randyficker 2013-04-23 17:14:24 UTC
Created attachment 3859 [details]
Repro code

Any activity that contains an AndroidGameView is never collected by the garbage collector.

I have attached a repro project that demonstrates this.  The project contains two activities, Activity1 and Activity2.  Activity1 just contains a button that launches Activity2.  

Activity2 is similar to the OpenGL sample project that ships with Xamarin.Android.  It simply creates an instance of AndroidGameView, however it also includes a button that calls Finish() so that you can close it to get back to Activity1.

The app also starts a new thread which invokes the garbage collector and prints out how much memory is being used every second.  

By repeatedly tapping the two buttons in the app, you can create and destroy Activity2s at will, and watch logcat to see the memory used by the app rise.  It's clear that the Activity2s that are created are never collected by the garbage collector.

This bug is already causing beta testers of my app to run their devices completely out of memory until they start getting OutOfMemoryExceptions.  This is a big problem, and I can't ship my app with this bug.

I'm running Xamarin.Android 4.6.00049.
Comment 1 dean.ellis 2013-04-26 09:03:04 UTC
I replicated the issue using the code provided. With the fix from the other bug raised on this issue (https://bugzilla.xamarin.com/show_bug.cgi?id=11921) and the following code in the second activity.

protected override void OnDestroy()
		{
			if (_gl != null) {
				_gl.Dispose();
				_gl = null;
			}
			base.OnDestroy();
		}

This seems to resolve the issue.