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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:05:02+00:00 2026-05-15T11:05:02+00:00

I know all instances of NSString are inmutable. If you assign a new value

  • 0

I know all instances of NSString are inmutable. If you assign a new value to a string new memory is addressed and the old string will be lost.

But if you use NSMutableString the string will always keep his same address in memory, no matter what you do.

I wonder how this exactly works. With methods like replaceCharactersInRange I can even add more characters to a string so I need more memory for my string. What happens to the objects in memory that follow the string? Are they all relocated and put somewhere else in memory? I don’t think so. But what is really going on?

  • 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-15T11:05:02+00:00Added an answer on May 15, 2026 at 11:05 am

    I know all instances of NSString are
    inmutable. If you assign a new value
    to a string new memory is addressed
    and the old string will be lost.

    That isn’t how mutability works, nor how references to NSStrings work. Nor how pointers work.

    A pointer to an object — NSString *a; declares a variable a that is a pointer to an object — merely holds the address in memory of the object. The actual object is [generally] an allocation on the heap of memory that contains the actual object itself.

    In those terms, there is really no difference at runtime between:

    NSString *a;
    NSMutableString *b;
    

    Both are references to — addresses of — some allocation in memory. The only difference is during compile time, b will be treated differently than a and the compiler will not complain if, say, you use NSMutableString methods when calling b (but would when calling a).

    As far as how NSMutableString works, it contains a buffer (or several buffers — implementation detail) internally that contain the string data. When you call one of the methods that mutate the string’s contents, the mutable string will re-allocate its internal storage as necessary to contain the new data.

    Objects do not move in memory. Once allocated, an allocation will never move — the address of the object or allocation will never change. The only semi-exception is when you use something like realloc() which might return a different address. However, that is really just a sequence of free(); malloc(); memcpy();.

    I’d suggest you revisit the Objective-C Programming Guide or, possibly, a C programming manual.

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

Sidebar

Related Questions

We all know T-SQL's string manipulation capabilities sometimes leaves much to be desired... I
We all know how to use <ctrl>-R to reverse search through history, but did
I know, this is basic stuff. But I get confused about this all the
For instance, I know that basically all languages that are object oriented based are
I wish to know all the pros and cons about using these two methods.
I want my program always know all of the mountpoints. After a quick google
I converted my whole site to XML/XSL and I would like to know all
There seems to be too many attributes/parameters in CSS... I want to know all
I have a background of programming in Java and C++, so I know all
I have this piece of code that is giving me trouble. I know all

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.