views:

8

answers:

1

The default iPhone view template has code as follows

{    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}

isnt there a memory leak here? shouldnt it be

{    

    // Override point for customization after app launch    
    [window addSubview:viewController.view];
    [viewController.view release];
    [window makeKeyAndVisible];

    return YES;
}
+2  A: 

There is no memory leak. You shouldn't call [viewController.view release] either.

The main reason is because the app delegate is not the owner of that .view. Only owners are responsible for -release'ing an object. The owner of that .view is the viewController.

(In general, you should never call -release on a property.)

KennyTM
As Kenny says, there is no leak. The view will be retained by the Window when it's added, but will be released when it's removed (whenever that may be), and then the view controller will release its view when it's deallocated, deallocating the view with it. No leak.
Jasarien