Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6322749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:23:28+00:00 2026-05-24T16:23:28+00:00

In the Xcode templates for iOS apps such as the ‘View Based Application’, a

  • 0

In the Xcode templates for iOS apps such as the ‘View Based Application’, a MainWindow nib is created with contains three top-level objects: The App Delegate, the Window, and the main View Controller. The App Delegate defines retain outlets/accessors for both the window and the view controller. I don’t understand why the App Delegate would need to retain these objects since they are already top-level objects in the nib and therefore should have been retained by UIApplication. Checking the retainCount of these objects sure enough shows 1 for the app delegate and 2 for the window and view controller. Could I/should I change these to assign instead?

I know this is a nit picky thing but I’m hoping that understanding why this is done will improve my overall understanding of memory management in iOS.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:23:30+00:00Added an answer on May 24, 2026 at 4:23 pm

    Assign is tricky in iOS with outlets I use @property (nonatomic, retain). Unlike in Mac OS, connected outlets to XIB objects in iOS are not automatically retained and memory managed, this may change with iOS 5, but is somewhat unlikely.

    The rationale there is so that you can release any view objects in – (void)viewDidUnload, and get rid of any views that you either don’t need, or can re-initialize on -(void)viewWillAppear. But the goal is, ostensibly, to keep you in control of what is collected and what is not.

    my pattern is to just declare normal cocoa accessors for them as I would for any other properties and set them to nil in the 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;
    }
    

    You are right, however in that it doesn’t really make much sense to have the retain for the window, but it makes sense for consistency IMHO. So long winded way of saying yes, in my experience the app delegate does need to retain the UIWindow or it can be collected in a memory sweep and cause somewhat random crashes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make my own iPhone Application Templates in XCode, based on
If I create a New Project in xcode, then choose View-based Application, the delegate
I'm trying to create a multi-view iOS (4.3) application in xcode 4 using the
Create default iPad split view based apps from template from xcode 4, then we
How would I change the initial templates created by Xcode when creating a new
I am learning how to create apps with multiple views using the Window-based application
I'm attempting to build my first universal iOS app using the default Xcode templates
I have read this question about the differences in the window- and view-based iOS
I could not find any Navigation Based Application template in Xcode. As of now,
I'm trying to build a PhoneGap-based application using Xcode 4. Since there's no PhoneGap

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.