Does the iOS app app delegate need to keep UIWindow?

In Xcode templates for iOS applications, such as a "view-based application", a MainWindow nib is created containing three top-level objects: the application delegate, the window, and the main view controller. The application delegate defines the retainoutputs / accessors for both the window and the view controller. I do not understand why the application delegate will need to save these objects, since they are already top-level objects in nib and therefore must be saved using UIApplication. To test retainCountthese objects, it is enough to show 1for the application delegate and 2for the window and view controller. Can I / change this to assigninstead?

I know this is a picky thing, but I hope that understanding why this is done will improve my general understanding of memory management in iOS.

+5
source share
1 answer

Assignment is difficult in iOS with conclusions. I use @property (non-atomic, save). Unlike Mac OS, connected outputs to XIB objects in iOS are not automatically saved and managed by memory, this may change from iOS 5, but it is somewhat unlikely.

, - (void) viewDidUnload , , on - (void) viewWillAppear. , , , , , .

, cocoa accessors , , nil viewDidUnload

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.buttonOne = nil;
    self.buttonTwo = nil;
    self.buttonThree = nil;
    self.buttonFour = nil;
    self.buttonFive = nil;
    self.buttonSix = nil;
    self.lineWidthSlider = nil;
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

, , , IMHO. "", , UIWindow, .

+1

All Articles