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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:54:03+00:00 2026-05-17T22:54:03+00:00

I wonder if return @Text; is autoreleased? And if it is so could you

  • 0

I wonder if

return @"Text";

is autoreleased? And if it is so could you please explain it.

Is the compiler creating a NSString object for us or how will the compiler handle this?

  • 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-17T22:54:03+00:00Added an answer on May 17, 2026 at 10:54 pm

    Constant NSStrings are compiled into the application binary. Releasing them is meaningless since the memory they use is readonly, does not come from the heap and cannot be recycled. If you look at the retain count of a constant NSString, you’ll see it is set to some astronomically high number (2^31-1 I think). The convention is that -release sent to an object with this retain count does nothing, neither does -retain. Consequently, sending -autorelease also does nothing except add the string to the autorelease pool (actually, even that might be optimised out).

    In terms of ownership (which is how you should be thinking about this), treat constant NSStrings exactly like anything else. You don’t obtain it using new, alloc, or copy, so unless you retain it, you don’t own it. So you also don’t need to autorelease it in your example before returning it.

    The caller should retain the return value, if it wants to keep it, even though -retain really does nothing. This makes your code more general, so if (for example) your method were changed to return a non constant NSString, you don’t have to worry about changing all the callers.

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

Sidebar

Related Questions

I wonder whether someone can help me please. I've put together this page, which
I wonder whether someone can help me please. I've put together this page which
I wonder whether someone may be able to help me please. I'm using this
I wonder under what conditions an NSHTTPURLResponse object will not have key @Content-Length ?
hey guys, i wonder how I could solve this in the best way: I
wonder if someone could help me with a little problem. I have session values
I wonder whether someone may be able to help me please. Firstly apologies as
I need to create a cross-site template object which will check the current time
Let's say that I have a boost::variant<std::string, int> myVariant; In this object I keep
I wonder whether someone may be able yo help me please. I've put together

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.