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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:27:52+00:00 2026-05-25T23:27:52+00:00

I think I understand retain/release in objective-C for the most part. However, I have

  • 0

I think I understand retain/release in objective-C for the most part. However, I have a specific case I am unsure about. Here is an example:

+ (NSString *)getPlayerNameByIndex:(NSInteger)globalIndex:(ABAddressBookRef)addressBook
{
    ...
    Player *player = [PlayerHelper loadPlayer:globalIndex];
    NSString *name = [PlayerHelper getPlayerName:player :addressBook];
    [player release];

    // 'retain' here?    
    return name;
}

+ (NSString *)getPlayerName:(Player *)player:(ABAddressBookRef)addressBook
{
    ...
    NSString *name = [[[NSString alloc] initWithString:player.nickname] autorelease];
    return name;
}

So then I call…

NSString *name = [PlayerHelper getPlayerNameByIndex:index:addressBook];
// name is 'autorelease'?

What I saw on random occasions is that the view sometimes shows the ‘name’ field as empty when it populates the table after coming back from another view. This could be another issue but I want to be sure of my use of ‘autorelease’.

The core of my question is the use of ‘autorelease’ in getPlayerName. Does the ‘autorelease’ state of being get passed through method getPlayerNameByIndex to the caller?

Or, do I have to call ‘retain’ in the intermediary method? I am thinking ‘autorelease’ may be releasing in method getPlayerNameByIndex.

Hopefully my question is clear. Any help is appreciated.

Update: Some more info for clarification…

NSError *error = nil;
Player *player = nil;
NSArray *array = [appDelegate.managedObjectContext executeFetchRequest:request error:&error];
if ([array count] == 1)
{
    player = [array objectAtIndex:0];
    [player retain];
}

This is essentially the “loadPlayer” method which loads info from core data. From the answers it sounds like I do not need to call [player retain], since it is an autorelated object, and I can simply return “player” and use it? Thanks for the responses!

  • 1 1 Answer
  • 1 View
  • 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-25T23:27:53+00:00Added an answer on May 25, 2026 at 11:27 pm

    The core of my question is the use of ‘autorelease’ in getPlayerName. Does the ‘autorelease’ state of being get passed through method getPlayerNameByIndex to the caller?

    The answer is yes.

    Or, do I have to call ‘retain’ in the intermediary method?

    whether you want to call retain depends on the semantics of your method.

    In Obj-C/Cocoa, the following convention applies: a method whose name begins with “alloc” or “new” or contains “copy” will return a retained object; otherwise you can expect to get an autoreleased object, then it is the caller responsibility to retain it according to its needs.

    I am thinking ‘autorelease’ may be releasing in method getPlayerNameByIndex.

    autoreleased objects are released at the next point in time when the autorelease pool is drained; this is usually associated to going back to the main loop (though, no details are available about this); so you can be pretty sure that auto-releasing does not kick in in getPlayerNameByIndex…

    Hope this helps clarifying the issue…

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

Sidebar

Related Questions

I think I am missing something about property attributes. First, I can't understand the
I think understand the idea of duck typing, and would like to use it
I think I understand the logic behind a delegate. I got more the problem
I think I understand the basic principals of T4 but I'm having a hard
I think I understand strong typing , but every time I look for examples
I think I understand the happened-before relationship for single variables. If I write a
I think I understand OSPF - it is Link-State routing, with a domain split
I understand the regular fixed-point type combinator and I think I understand the higher-order
So I (think I) understand the difference between Float, Double, and Decimal , but
I must admin this is kind of funny even though I think I understand

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.