Bug 92 - ViewController is not collected unless I remove custom UIButton from subview
Summary: ViewController is not collected unless I remove custom UIButton from subview
Status: RESOLVED DUPLICATE of bug 57
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 4.x
Hardware: Macintosh Mac OS
: --- major
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-07-27 13:50 UTC by Andrew Young
Modified: 2011-07-28 23:30 UTC (History)
2 users (show)

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

Sample project illustrating the bug. (11.58 KB, application/zip)
2011-07-27 13:50 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-07-27 13:50:38 UTC
Created attachment 25 [details]
Sample project illustrating the bug.

I asked this same question in StackOverflow but I have a hunch that this is a bug in the MonoTouch runtime. See here for the question. It pretty much explains everything.


But in short, my view controller and all it's subviews are not being garbage collected unless I remove my custom UIButton from the view. If you comment out line 66 in MyViewController.cs you'll see that none of the finalizers will be called when you perform the following test.

1. Compile and run the attached proj in the simulator
2. Touch the button "Push a new controller"
3. Go back in the nav controller (popping a view controller off the stack)
4. Verify that the finalizers are being run by seeing console writes

Note: running on the device, you'll have to touch the "Collect Garbage" button before the objects will be finalized which is fine since I'm not supposed to know when garbage collection occurs anyway. But commenting out line 66 causes all of my objects to not be candidates for GC.
Comment 1 Andrew Young 2011-07-27 13:52:50 UTC
Also, notice that none of the other subviews need to be removed. Lines 65 and 67 are commented out and it works just fine.
Comment 2 Miguel de Icaza [MSFT] 2011-07-28 23:30:30 UTC
This is a duplicate of #57;   Fix will be on the next release, and the stackoverflow post has a workaround

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