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 6188959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:19:30+00:00 2026-05-24T02:19:30+00:00

I have an attendant question to iPhone: Why do I need self.<> in viewDidUnload?

  • 0

I have an attendant question to iPhone: Why do I need self.<> in viewDidUnload?

Since there is a difference between using self.instance and instance, when is only instance actually used? Just setting the reference to nil seems quite useless? Why is the option there?

  • 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-24T02:19:31+00:00Added an answer on May 24, 2026 at 2:19 am

    Generally, you’ll find a lot of useful information here: http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html%23//apple_ref/doc/uid/TP40004447-SW4

    For the rest of this answer, I’ll assume that you are referring to properties automatically synthesised with the @synthesize directive in your .m files.

    Executive summary

    When you use the form self.property, retain/release is automatically taken care of for you. When you use the form instanceVariable without the self prefix, you’re on your own with retain/release.

    Longer explanation

    When you omit the “self.” part, what you really are doing is that you access the automatically generated underlying ivar which the compiler has given the same name as you have given to the property.

    If you don’t want the compiler to generate ivars of the same name, then you can use an extended form of the @synthesize directive, like this:

    @synthesize myvariable=__myvariable;
    

    That way, you will ask the compiler to create an underlying ivar called __myvariable instead of the default myvariable.

    Using this extended form, you would refer to either self.myvariable (as a property) or __myvariable (as an instance variable), which can be handy to visually distinguish the two types of access.

    With that in place, we can get to the substance of the matter.

    When you use self.myvariable, you implicitly call the accessor methods (possibly synthesised for convenience), like this:

    self.myvariable = @"Some string";
    

    is equal to

    [self setMyvariable: @"Some string"];
    

    or, in the case of a right hand use of the property

    myLocalVar = self.myvariable;
    

    is equal to:

    myLocalVar = [self myvariable];
    

    The examples above use the accessor names recommended by Apple.

    On the other hand, when you use the instance variable directly, you just assign the variables directly without going through the accessors.

    Now, one huge advantage of using the accessors on the iPhone is that the automatically synthesised accessors also take care of the retain/release messages, so you don’t have to worry about that – or waste code lines handling this somewhat tedious stuff.

    Since there is no need to worry about retain/release when you are just reading a property, you could argue that you only need to use the property syntax (with self.) on the left side of an assignment, so whether you want to use the self.-syntax on the right hand side of an assignment is partly a matter of style.

    Personally, I have developed a style where I try not to refer to automatically synthesised ivars, unless I have specified them in the @synthesize directive. Otherwise Apple might one day change the way an unspecified @synthesize directive works, and my builds would break. But that is just a personal precaution of mine.

    There is one exception to all this, as stated in the docs linked at the top of this answer – and that is that you should not use accessors to the class’ own instance variables in the init* methods. One the Mac, you shouldn’t use them in the dealloc methods, either, but this is one point where Apple’s coding recommendations differ between the two platforms.

    Ok, this was a long answer to just say, read the docs, but I hope it clarifies things a little. Memory management in reference counted environments is not trivial, so don’t despair if it isn’t clear at first.

    PS: And if you think this the sort of worries that others should solve for you, log a bug with Apple to ask for garbage collection on iOS. It works nicely on 64-bit OS X.

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

Sidebar

Related Questions

This is not SO Meta question. I am using SO only as example. In
This is somewhat an attendant question to Do I need to release xib resources?
Have just started using Google Chrome , and noticed in parts of our site,
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I have written a stored procedure, & to execute this procedure I need to
I have multiple models that need to have their history kept pretty much indefinitely
Here is my problem (I'm using SQL Server) I have a table of Students
I have my attend method below currently in my controller. My question is how
I have about 20 events (UK based if that makes a difference). I will

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.