Bug 1840 - GC not cleaning up NavController
Summary: GC not cleaning up NavController
Status: RESOLVED DUPLICATE of bug 1889
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Rolf Bjarne Kvinge [MSFT]
Depends on:
Reported: 2011-11-02 15:05 UTC by Andrew Young
Modified: 2012-02-22 19:00 UTC (History)
3 users (show)

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

sample proj (11.50 KB, application/zip)
2011-11-02 15:05 UTC, Andrew Young

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 Andrew Young 2011-11-02 15:05:00 UTC
Created attachment 810 [details]
sample proj

I have a sample project that shows that a navigation controller, including everything pushed onto the nav controller, is not being cleaned up by the GC.

Steps to reproduce:
1. Run the sample proj in the simulator with debugging
2. Touch the "Show Modal" button.
3. Cancel out of the modal.
4. Do steps 2 and 3 again.
5. Verify that nothing is printed in the console saying anything about a controller being finalized. If GC collected the object you should expect something printed to console.

To cause GC to clean up the nav controller replace lines 67 and 68 with these lines:

_myNavController = new MyNavController(_nextController);
PresentModalViewController(_myNavController, true);

Perform the same test case above and verify things work as expected.
Comment 1 Andrew Young 2011-11-02 15:05:44 UTC
I'm on MonoTouch 5
Comment 2 Andrew Young 2011-11-02 15:33:11 UTC
An update to my first comment: lines 67 and 68 refer to the MyViewController.cs file.

Additionally, I've found that line 101 in MyViewController is key to hinting to the GC that there are no more references and to go ahead and clean things up. I shouldn't have to do line 101. Seems like a hack, right?
Comment 3 David Jade 2012-02-17 19:56:03 UTC
I am finding these same sorts of things when presenting modal as well. What I usually have to do to get things to GC is something like this (where dialog is a MonoTouch.Dialog DialogViewController):

	var Controller = new UINavigationController(dialog);

	dialog.NavigationItem.LeftBarButtonItem.Clicked += delegate

		Controller = null;

I think that the Dispose() above should not be necessary but if I don't do this, the whole controller chain and everything else it hangs onto (in my case MonoTouch.Dialog elements, views, etc...) never get released. If I present my dialog multiple times, the memory used just grows and grows.

I am on MT 5.2.5 

Note: I still see this behavior regardless of whether Bug# 3462 is involved or not.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2012-02-22 19:00:27 UTC

*** This bug has been marked as a duplicate of bug 1889 ***