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

  • Home
  • SEARCH
  • 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 7886565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:21:01+00:00 2026-06-03T05:21:01+00:00

Though I’m sure they exists, I’m having difficulties finding or pinning down an official

  • 0

Though I’m sure they exists, I’m having difficulties finding or pinning down an official best practice for declaring outlets in a ViewController.

There are 3 options so far as I can see:

  1. ivar only
  2. property only
  3. property backed with an ivar

Xcode currently crashes when I try and auto-generate a property by dragging into my ViewController from IB, but from what I remember, doing so creates a property without an ivar. It is also possible to drag into the ivar section and this will create an ivar without a property. This suggests that property-only and ivar only outlets are both OK with apple.

So in viewDidUnload we need to assign nil to any of our outlets, but what about dealloc. If we have used a property without an ivar, how can we release our outlet give that we are not supposed to use any accessors in an init or dealloc?

It seems to me that the only pattern which would allow us to release our outlet without an accessor is using a property backed with an ivar, so we can manually release our ivar in dealloc without using its accessor, however this is the one option which Apple’s code-generation doesn’t support.

  • 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-06-03T05:21:03+00:00Added an answer on June 3, 2026 at 5:21 am

    As a rule of thumb, I usually create accessors for IBOutlets.

    In ARC or non-ARC projects I usually do the following:

    //.h (ARC)
    @property (nonatomic, weak) IBOutlet UILabel* myLabel;
    
    //.h (non-ARC)
    @property (nonatomic, retain) IBOutlet UILabel* myLabel;
    
    //.m
    @synthesize myLabel;
    

    In this manner you can let the compiler to create an instance variable for you. But you can also declare your instance variable and tell the compiler to use that.

    Then you can use that accessors/instance variable wherever you want.

    The Apple Memory Management guide says that you have to avoid accessors methods in init or dealloc methods when you have non-ARC projects. So, for example:

    // (non-ARC)
    - (void)dealloc
    {
       [myLabel release]; myLabel = nil; // I'm using the instance variable here!
       [super dealloc];       
    }
    

    This is very important in non-ARC projects. The reason is that, if there is no accessor, KVC will assign the nib object to the instance variable and will put a retain on it. If you forget to release it, you could have a memory leak. Using an accessor force you to release that object at the end.

    I strongly suggest to read friday-qa-2012-04-13-nib-memory-management by Mike Ash. It’s a very cool article on nib and memory management.

    Hope it helps.

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

Sidebar

Related Questions

Even though its origin stickmanlabs.com seems to be down, lightwindow remains a popular javascript
Though it's debatable, I've heard the majority of CSS developers prefer multi-line because of
Though it's on the edge of programming questions, I think this is still relevant
though I have visited this site many times, this is my first question. After
Though the title says everything, I want to let you know the particular scenario
though the code is a little long, most of them are very simple IMO.
Though internal, I presumed that it is safe to use ConcurrentIdentityWeakKeyHashMap generally. However, the
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even though I've been a developer for awhile I've been lucky enough to have

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.