Skip navigation.
 
mlRe: Correct use of NSViewController
FROM : Steve Weller
DATE : Sat Mar 22 04:31:05 2008

On Mar 21, 2008, at 2:31 PM, Cathy Shive wrote:
> 1,  window is about to close (wish there was a more reliable place 
> to do this, but it has to be before dealloc):
>
> windowController:
>
> - (void)windowWillClose
> {
>     [mViewController removeObservations]; // this causes the method to 
> be called all the way down the view controller tree
> }
>
> 2.  view controller removes it's observations
>
> viewController:
>
> - (void)removeObservations
> {
>     [wArrayController removeObserver:self forKeyPath:@"selectedObjects"];
>     [super removeObservations];
> }
>
> 3.  The document closes and the window controller is released and 
> dealloced:
>
> window controller:
> - (void)dealloc
> {
>     [mViewController release];
>     [super dealloc];
> }
>
> 3.  The first view controller is released and dealloced:
>
> viewController:
> - (void)dealloc
> {
>     [mSubcontrollers release];
>     [super dealloc];
> }


I do a very similar thing, but name things differently. Instead of 
telling the lower objects what to do (remove observations) I tell them 
what is happening at the high level so they can do their own thing 
based on that (window is closing.. so I'll remove my observers). This 
lets me keep everything out of dealloc except for memory management. 
In that way if I switch to GC it will still work.


--
Blog:    Photos: <A href="http://bagelturf.smugmug.com/">http://bagelturf.smugmug.com/

Related mailsAuthorDate
mlCorrect use of NSViewController Jonathan Dann Mar 19, 12:37
mlRe: Correct use of NSViewController Cathy Shive Mar 19, 13:19
mlRe: Correct use of NSViewController Jonathan Dann Mar 20, 02:19
mlRe: Correct use of NSViewController Cathy Shive Mar 20, 08:40
mlRe: Correct use of NSViewController Jonathan Dann Mar 20, 12:35
mlRe: Correct use of NSViewController Cathy Shive Mar 20, 13:29
mlRe: Correct use of NSViewController Paul Szego Mar 20, 23:27
mlRe: Correct use of NSViewController Jonathan Dann Mar 21, 21:49
mlRe: Correct use of NSViewController Cathy Shive Mar 21, 22:31
mlRe: Correct use of NSViewController Steve Weller Mar 22, 04:25
mlRe: Correct use of NSViewController Steve Weller Mar 22, 04:31
mlRe: Correct use of NSViewController Cathy Shive Mar 22, 05:18