Dispose is not a good place to put cleanup stuff for views or view controllers. There are too many situations in which you can't call Dispose directly and have to rely instead on the finalizer. Remember, if your Dispose(bool) method is called from a finalizer (where the bool argument is false) then it is not safe to do pretty much anything. You can't look at any managed objects referenced by your object because they may already be dead.
For view controllers use ViewWillAppear and ViewDidDisappear. For views use DidMoveToWindow (do init when the window is not null and cleanup when the window is null). -- Adam Kemp [email protected] From: Len Charest <[email protected]> To: Nic Wise <[email protected]>, Cc: monotouch <[email protected]> Date: 02/20/2013 11:40 AM Subject: Re: [MonoTouch] Disposing view controllers Sent by: [email protected] Sure, but Dispose seems like an attractive alternative to the deprecated ViewDidUnload method for hosting cleanup logic that you'd like to execute immediately. On Tue, Feb 19, 2013 at 12:23 PM, Nic Wise <[email protected]> wrote: I've never bothered, and it's never been an issue. Just make sure you are not holding a reference to it anywhere, and the GC should clean it up for you. On 19 February 2013 17:24, Len Charest <[email protected]> wrote: > Is it necessary and/or best practice to dispose view controllers that have > been popped off of a navigation controller? E.g., programmatically: > > myNavigationController.PopViewControllerAnimated(true).Dispose(); > > If so, what is the best way to capture a reference to the controller that is > popped when the user touches the back button? (A back button touch does > result in a call to PopViewControllerAnimated, but the nav bar delegate does > not pass a reference to the target controller in its DidPopItem method.) > > Thanks, > Len > > _______________________________________________ > MonoTouch mailing list > [email protected] > http://lists.ximian.com/mailman/listinfo/monotouch > -- Nic Wise t. +44 7788 592 806 | @fastchicken b. http://www.fastchicken.co.nz/ _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch _______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
