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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:28:53+00:00 2026-05-12T10:28:53+00:00

This question follows on from a previous question, that has raised a further issue.

  • 0

This question follows on from a previous question, that has raised a further issue. What I am trying to understand is just when the pointers and object in this example are being created and what ultimately happens to them. I am still trying to get my head round this, so please excuse any false assumptions I may have made.

// MAIN
int main (int argc, const char * argv[]) {
    PlanetClass *newPlanet_01 = [[PlanetClass alloc] init];
    [newPlanet_01 setGeekName:@"StarWars"];
}

.

// CLASS
@interface PlanetClass : NSObject {
    NSString *geekName;
}

- (NSString*) geekName;
- (void) setGeekName:(NSString*)gName;
@end

.

// SETTER
- (void)setGeekName:(NSString *)gName {
    if (geekName != gName) {
        [geekName release];
        geekName = [gName copy];
    }
}

(A) … When an instance of PlanetClass “newPlanet_01” is first created is the NSString instance variable object created, or just a pointer to a possible future object? If it is just a pointer what am I releasing later in the setter as its just a pointer, not a pointer to an object?

(B) … In the above example “gName” is a pointer to the NSString object @”StarWars”?

(C) … Next is the pointer geekName different from the gName (i.e. if geekName does not already point at @”StarWars”)

(D) … geekName release, what is released the first time the code is run, my understanding was that geekName is just a pointer to does not point to anything. Or does release just not release anything this first time?

(E) … Finally geekName = [gName copy]; the newly released geekName is now assigned to point to a copy of gName, what happens to the original gName?

  • 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-12T10:28:53+00:00Added an answer on May 12, 2026 at 10:28 am
    1. You’re creating a pointer that is initialized to nil. If you’re familiar with C or Java, then nil is basically the same thing as NULL or null — it’s effectively a pointer to nothing.
    2. Yes. @"StarWars" is called a “string literal”. Think of a string literal as a “permanent” string that is stored by the program, and gName (in this case) is a pointer to the memory location of that string.
    3. Yep — that line makes sure that the incoming gName is not the same as the object’s geekName variable. Assume that check wasn’t there, and gName and geekName pointed to the same string — then the next line would release that string, which could make the next line invalid (it would be copying a released string — very bad!).
    4. Assuming geekName is still nil, then yes, nothing is released; or rather, the release message is sent to the nil object, which does nothing with the message. (Unlike C or Java, in Objective-C, you can send messages to nil — but all such messages are ignored, and nil is the return value from all such messages).
    5. You create a copy of gName in case gName is really an instance of an NSMutableString — you don’t want other code to mutate the string that you are treating as immutable. But what happens to the original object pointed to by gName? Well, it depends on what the caller does with it. It could be released, it could be retained, it could be passed to another object…you don’t really know. In this particular case, since gName points to the string literal “StarWars”, nothing happens to that object (since it’s a string literal — see above). And the pointer itself is only valid in the scope of this method, and goes away once the method returns.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, this kind of follows on from my previous question . What I would
This question follows on from a previous question. However stackoverflow presents me from commenting
This follows on from my previous question about Moose structured types. I apologise for
This question follows on from this vim search question I have a setting in
This follows on from this question where I was getting a few answers assuming
this kind of follows on from another question of mine. Basically, once I have
This question is a follow-up from How to indicate that a method was unsuccessful
This is a continuation question from a previous question I have asked I now
(This is a follow-up from this previous question ). I was able to successfully
A continuation from this question I need a SQL statement that returns the number

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.