Bug 5005 - RemoveObserver must be called multiple times for object to be garbage collected
Summary: RemoveObserver must be called multiple times for object to be garbage collected
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-05-10 11:55 UTC by Philip Richardson
Modified: 2012-05-10 18:27 UTC (History)
2 users (show)

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

Test for Add and RemoveObserver (24.78 KB, application/zip)
2012-05-10 11:59 UTC, Philip Richardson

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 Philip Richardson 2012-05-10 11:55:21 UTC
If an NSObject is added to more than one notification list in NSNotificationCenter.DefaultCenter, it must call RemoveObserver once for each AddObserver call to be properly disposed of. The first time RemoveObserver is called, it is removed from every notification list, but isn't garbage collected until RemoveObserver is called the same number of times AddObserver is called.

Attached is an example project I used to test this behavior.
Comment 1 Philip Richardson 2012-05-10 11:59:56 UTC
Created attachment 1850 [details]
Test for Add and RemoveObserver
Comment 2 Rolf Bjarne Kvinge [MSFT] 2012-05-10 18:27:26 UTC
Fixed in monotouch master (1e5630d), unit tests included. The next release with this fix will be 5.3.4.

For now you can just use the workaround you found yourself (call RemoveObserver multiple times).

Thanks for the perfect test case!