Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
Created attachment 810 [details]
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);
Perform the same test case above and verify things work as expected.
I'm on MonoTouch 5
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?
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.
*** This bug has been marked as a duplicate of bug 1889 ***