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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:12:26+00:00 2026-05-14T03:12:26+00:00

If I create a String with [NSString StringWithFormat], do I have to [retain] it?

  • 0

If I create a String with [NSString StringWithFormat], do I have to [retain] it?
My understanding is that convenience methods add the objects to autorelease pool. If that is the case, shouldn’t we retain the object so that it doesn’t get drained with pool at the end of the event loop?

  • 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-14T03:12:26+00:00Added an answer on May 14, 2026 at 3:12 am

    If the string should persist beyond the current function, then yes, the object that needs it should retain it. Here’s one of those places where the English phrasing seems trivial but is actually concealing a key concept. Rather than saying “do I have to retain it?” or (as I originally wrote) “if you want the string to persist,” talk in terms of an object retaining the string. The difference is the latter expresses the concept of ownership (note: the Apple documentation uses “you” when talking of ownership, but it’s a third-person neuter “you” rather than a second-person “you”). Of course, if you’re storing the string in a property, then retaining (or copying) is handled for you. Unless you need to target older versions of OS X (10.4 and earlier), you should generally be using properties.

    The standard collections own the objects they contain, and thus retain them. When an element is removed from a collection, the collection releases the element (note: they don’t autorelease, so if the object has no other owners, the object will be destroyed). Read more about this topic in “Validity of Shared Objects“. Apple’s memory management documentation should tell you everything you need to know.

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

Sidebar

Related Questions

I use NSString stringWithFormat method for create an URL string. But now I have
I have a string wDevCopyright = [NSString stringWithFormat:@Copyright: %c 1995 by WIRELESS.dev, Corp Communications
NSString *phoneNumber = @2310234432; I would like to create a new string out of
Is there any way to create a new NSString from a format string like
How do I create a string so that it formats floating point numbers to
I want to create a string in JavaScript that contains all ascii characters. How
I have an array of objects that I want to save as a file
I want to create a comma-separated string like this. NSString *list = @iPhone,iPad,iPod; I
I am trying to create a string with parameters that I pass to a
I have a NSURLRequest created next way: NSString *url=[NSString stringWithFormat:@http://myserveradress.com/api/users/register?register_password=%@&register_password_confirm=%@&register_email=%@&register_terms=1&register_user=%@&process_registration=1&register_name=%@ , [password stringByReplacingOccurrencesOfString:@ withString:@%],[confirm

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.