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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:33:54+00:00 2026-05-21T23:33:54+00:00

I’m going through all of my documentation regarding memory management and I’m a bit

  • 0

I’m going through all of my documentation regarding memory management and I’m a bit confused about something.

When you use @property, it creates getters/setters for the object:

.h:
@property (retain, nonatomic) NSString *myString

.m:
@synthesize myString

I understand that, but where I get confused is the use of self. I see different syntax in different blogs and books. I’ve seen:

myString = [NSString alloc] initWithString:@"Hi there"];

or

self.myString = [NSString alloc] initWithString:@"Hi there"];

Then in dealloc I see:

self.myString = nil;

or

[myString release];

or

self.myString = nil;
[myString release];

On this site, someone stated that using self adds another increment to the retain count? Is that true, I haven’t seen that anywhere.

Do the automatic getters/setters that are provided autorelease?

Which is the correct way of doing all of this?

Thanks!

  • 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-21T23:33:55+00:00Added an answer on May 21, 2026 at 11:33 pm

    If you are not using the dot syntax you are not using any setter or getter.

    The next thing is, it depends on how the property has been declared.

    Let’s assume something like this:

    @property (nonatomic, retain) Article *article;
    ...
    @synthesize article;
    

    Assigning something to article with

    self.article = [[Article alloc] init];
    

    will overretain the instance given back by alloc/init and cause a leak. This is because the setter of article will retain it and will release any previous instance for you.

    So you could rewrite it as:

    self.article = [[[Article alloc] init] autorelease];
    

    Doing this

    article = [[Article alloc] init]; 
    

    is also ok, but could involve a leak as article may hold a reference to an instance already. So freeing the value beforehand would be needed:

    [article release];
    article = [[Article alloc] init]; 
    

    Freeing memory could be done with

    [article release];
    

    or with

    self.article = nil;
    

    The first one does access the field directly, no setters/getters involved. The second one sets nil to the field by using a setter. Which will release the current instance, if there is one before setting it to nil.

    This construct

    self.myString = nil; 
    [myString release];
    

    is just too much, it actually sends release to nil, which is harmless but also needless.

    You just have to mentally map hat using the dot syntax is using accessor methods:

    self.article = newArticle
    // is
    [self setArticle:newArticle];
    

    and

    myArticle = self.article;
    // is
    myArticle = [self article];
    

    Some suggestions on reading, all official documents by Apple:

    The Objective-C Programming Language

    • Dot Syntax
    • Declared Properties

    Memory Management Programming Guide

    • Object Ownership and Disposal
    • Using Accessor Methods
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I would like to count the length of a string with PHP. The string

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.