You should use ViewWillAppear() and ViewDidDisappear() instead. René
Am 25.09.2012 um 10:51 schrieb slodge <[email protected]>: > Thanks Adam > > Interesting feedback > >> So what do you do with the code in that function? > > If my UIViewController is (pseudocode): > > class MyUIVC > { > void ViewDidLoad() > { > ApplicationSingleton.Messages += MessageHandler; > } > > void MessageHandler(s, e) > { > // do stuff... > } > } > > Obviously if my viewcontroller never unsubscribes then the from the > ApplicationSingleton.Messages event, then the C# viewcontroller object will > never get garbage collected... > > So I'm currently wondering what 'uikit' hooks are available in which my > viewcontroller can unsubscribe. > > Currently, I guess some of my options are: > > - unsubscribe in the Dispose(bool) override - but be aware that this will > only get called after a memory alert has triggered - so it's not optimal and > you could have a lot of event subscriptions hanging around. > - consider using WeakReferences for the events - again not optimal (and also > a bit nasty to debug IMO) > - rearchitect the application behaviour to somehow use ViewDidAppear and > ViewDidDisappear (I think this is probably the best thing to do - I just > need to do some testing across tabs, splits, navigations, modals, popups, > etc to remind myself exactly when these selectors get called in a view > hierarchy) > - rearchitect the application behaviour to somehow use the > NavigationController Delegate > > Actually writing this all down has really helped me make my own mind up - > very therapeutic - thanks :) > > Stuart > > P.S. I don't think my previous ViewDidUnload() handler was a good place to > unsubscribe either -so I'm glad this change is forcing me to look at the > architecture again :) > > > > -- > View this message in context: > http://monotouch.2284126.n4.nabble.com/Obsolete-methods-in-iOS-6-tp4657100p4657214.html > Sent from the MonoTouch mailing list archive at Nabble.com. > _______________________________________________ > MonoTouch mailing list > [email protected] > http://lists.ximian.com/mailman/listinfo/monotouch _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
