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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:07:37+00:00 2026-05-24T20:07:37+00:00

Possible Duplicate: Properties and Instance Variables in Objective-C 2.0 I’m using properties only for

  • 0

Possible Duplicate:
Properties and Instance Variables in Objective-C 2.0

I’m using properties only for ivars that don’t require any real validation when getting or setting a value for a class that I’m authoring.

Ex: 
@interface ClassB : NSObject
{
    // No ivars
}

@property (nonatomic, retain) ClassA *obj;
@property (nonatomic, retain) NSString *str;

Whenever I call these methods within the class I’m always using self.obj/self.str or [self obj]/[self str]. This way in order to set the state of the object you are forced to go through the property so that the references are more carefully managed by the compiler produced getters and setters. With that said, are there any problems that I can run into creating my classes this way? Also, with no ivar present, is any “release” needed in an overwritten “dealloc” method in the @implementation file?

  • 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-24T20:07:39+00:00Added an answer on May 24, 2026 at 8:07 pm

    If you’re using the @synthesize directive to create the property accessors, the compiler will also create any ivars that you leave out of the class declaration. You do still need to release your ivars. It used to be that you couldn’t access synthesized ivars directly and so had to use the property setter in your -dealloc method like this:

    - (void)dealloc
    {
        self.obj = nil;
        self.str = nil;
        [super dealloc];
    }
    

    These days, though, the compiler will let you access the synthesized ivar directly, so you can release it instead of calling the setter (which is a good idea in -dealloc, and a bad idea everywhere else):

    - (void)dealloc
    {
        [obj release];
        [str release];
        [super dealloc];
    }
    

    This will change when you eventually convert your code for ARC (automatic reference counting) because the compiler will take care of releasing your ivars in -dealloc for you. Most of the time, this means that your -dealloc implementation can just go away.

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

Sidebar

Related Questions

Possible Duplicate: Properties declared as instance variables too? Let's say I have an objective
Possible Duplicate: Properties vs Methods Is there any rule or general best practice as
Possible Duplicate: Objective-C properties: atomic vs nonatomic By default all properties in Objective-C are
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: When do you use the “this” keyword? Hello, I understand that the
Possible Duplicate: Comparing object properties in c# Let's say I have a POCO: public
Possible Duplicate: Properties vs Methods In method you can type some code and in
Possible Duplicate: Properties vs Methods For many situations it is obvious whether something should
Possible Duplicate: iPhone - file properties Hi all. i m creating an application which
Possible Duplicate: Escaping equal sign in properties files In a .properties file, can I

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.