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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:25:02+00:00 2026-05-24T07:25:02+00:00

Basic question here. Say in my .h, I define a NSString: @interface MyGreatClass @property

  • 0

Basic question here.

Say in my .h, I define a NSString:

@interface MyGreatClass
@property (nonatomic, retain) NSString *myAwesomeString;
@end

And then in my .m, I have the following code:

@implementation MyGreatClass
@synthesize myAwesomeString
-(void)dealloc{
    [myAwesomeString release];
}
-(void)viewDidLoad{
    self.myAwesomeString = [[NSString alloc] initWithString:@"Yay"];
}
@end
  1. Did I leak? I know, I know, whenever you call retain or alloc
    on a method, it increases the counter in memory by one and you need
    to have a release statement for each retain and alloc, so I
    suspect I do, but I am just making sure because if this is true, I
    have to do this for a crapload of variables in my app. Also if you
    do have to call release twice, where do I call the second release?
    Can I call both of them in dealloc, one right after the other?

  2. How nesesarry is the self. in front of variables when referring to properties of the class
    you are in? What happens if you don’t have it and when exactly is it
    necesarry?

  • 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-24T07:25:02+00:00Added an answer on May 24, 2026 at 7:25 am

    Yes, that will leak because it’s overretained. The four standard correct solutions are:

    // Solution 1:
    NSString *stringToBeAwesome = [[NSString alloc] initWithString:@"Yay"];
    self.myAwesomeString = stringToBeAwesome;
    [stringToBeAwesome release];
    
    //Solution 2:
    self.myAwesomeString = [[[NSString alloc] initWithString:@"Yay"] autorelease];
    
    // Solution 3:
    self.myAwesomeString = [NSString stringWithString:@"Yay"];
    
    // Solution 4:
    myAwesomeString = [[NSString alloc] initWithString:@"Yay"];
    

    You’ll notice the last one doesn’t start with self., which brings us to your second question. If you don’t write self., you are not accessing a property. That myAwesomeStirng in Solution 4 is an instance variable, accessed directly. It won’t go through the property accessors, so it won’t retain the value you assign and it won’t release any value that the variable held before.

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

Sidebar

Related Questions

This is a very basic question...quite embarassing, but here goes: I have a Stopwatch
I have a question that seems basic, but I can't figure out. Say that
Here’s a really really super-basic question. Say I wanted to build – today –
Here one more basic question asked in MS interview recently class A { public
Very basic question - but I couldn't find an answer. I have got a
I think this is a pretty basic question, but here it is anyway. I
I have another SQL/access 2007 question that seems really basic but I'm not sure
Probably a very newb C++ question. Say I have a class, vertex, with several
I have a pretty basic question that I imagine would require a join to
Very simple math question. Say I have an image with a point being tracked

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.