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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:22:04+00:00 2026-06-06T16:22:04+00:00

In my research I’ve come across something peculiar. @interface Class { NSString *_string }

  • 0

In my research I’ve come across something peculiar.

@interface Class {
    NSString *_string
}

- (void) Method1 {
    _string = @"ASDF";
}

Intially I thought that _string was part of the autorelease pools and really didn’t think about the memory aspect of it.

After reading this SO post Objective C NSString* property retain count oddity
I’ve realized that no, this is not the case, and that the retain count of _string is actually UINT_MAX

Obviously my thinking that _string was part of the autorelease pool was a fluke, and how I handled the variable just somehow worked out. What I would like to know, though, is: when does @"ASDF" get thrown away? I know I should be using properties and setters, but there is probably a lot of code out there that looks like this since assigning a constant to a variable is so intuitive.

What is the lifecycle of these immutable, literal NSStrings, and when will [_string length] actually return an error since @"ASDF" doesn’t reside in memory anymore?

  • 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-06-06T16:22:06+00:00Added an answer on June 6, 2026 at 4:22 pm

    From Is a literal NSString autoreleased or does it need to be released?

    Compiler allocated strings (of the format @”STRING”) are constant, and
    so -retain, -release, and -autorelease messages to them are ignored.
    You don’t have to release or autorelease foo in this case (but it
    won’t hurt).

    Under the hood when you do

    NSString* yourString = @"ABC";
    

    the string will be stored in a area of memory called data segment. This area never changes after the application is launched. Here strings are treated as constants for your app. At the same time a string is an object, so if you want to keep it you call retain or copy.

    On the contary when you do

    NSString* yourString = // alloc-init
    

    you create an object on the heap. If you forget to release you have a memory leak. If someone else destroy it, and you try to access it, you have a bad access to that memory location.

    Hope that helps.

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

Sidebar

Related Questions

I have been doing research on HTML canvas libraries and I came across this
After some research on the web without success, I come here to ask you
im doing research project for a the game Text twist,the text will automatically search
I did some research and found that the only way to vertically center a
After many hours of research and tinkering, I've finally managed to get backbone.js routes
I'm doing some research and I'm playing with Apache Mahout 0.6 My purpose is
I am doing some research on developing thread safe applications. I know users can
I've done some research, but I didn't find an answer to my question. I
I am a research student who just started the android programming for 3 weeks
So after extensive research and tons of jQuery and Javascript solutions I simply could

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.