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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:15:32+00:00 2026-05-22T20:15:32+00:00

This maybe too basic but I couldn’t find an exact answer. I’ll be happy

  • 0

This maybe too basic but I couldn’t find an exact answer. I’ll be happy to delete/close this post if anyone point me to similar posts.

I want to call method “getString” to return a formatted string and set to my label like this:

-(NSString*) getString {
  NSString *result = [NSString stringWithFormat:@"blah blah %@", someOtherString];
  return result;
}

-(void) viewDidLoad {
  someLabel.text = [self getString];
}

This code worked for me, but I am concerned that result is allocated by a convenient method thus may be auto-released before it got retained by the label. Is it true? If so, when exactly would an object from convenient method get released?

Second question, if in case I have to use [NSString alloc] to create my own string object. Where and how should I release it?

Thanks in advance
Leo

  • 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-22T20:15:33+00:00Added an answer on May 22, 2026 at 8:15 pm

    It isn’t true that the object will be autoreleased before you retain it. The details of when the pool gets drained are unimportant to answer this question, except that it can’t happen during your code unless you call drain or release on the pool. If your function calls another function, except in some specific edge cases both the function you call and the function you called from need to exit before that thread can do anything else. The autorelease pool is thread-specific.

    To answer your second question, if you alloc an object you should release it when you’ve finished using it. Simple as that. That includes when you pass it to other code that needs it, because it should be up to that other code to claim ownership if it needs to.

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

Sidebar

Related Questions

I know this maybe a basic question but I just can't seem to find
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
I've looked at this but it wasn't too much help. Maybe I didn't read
This question may be too product specifc but I'd like to know if anyone
I know this maybe a very basic question but I'm having a bit of
I know this is a basic question, but I can't seem to find an
This maybe a stupid question, but as I can not easily undo my change
Maybe this is a dumb question, but is there any way to convert a
This is probably way too vague for any concrete answers, but this issue has
i'm a long-time newbie to c#, and this question may be too obvious, so

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.