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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:41:30+00:00 2026-05-25T18:41:30+00:00

I have questions about the NSString pointer. I wanted to get to the bottom

  • 0

I have questions about the NSString pointer. I wanted to get to the bottom of this and actually tried to create a theory to obtain full understanding based on multiple information retrieved from then net. Please believe me when I say that I have not been lazy, and I actually read a lot, but I was still left with uncertainties and questions. Can you please confirm / deny when good / wrong, and I’ve put additional questions and doubts which are indicated by (?).

Here we go:
If I consider this very basic example:

NSString *sPointer = [[NSString alloc]initWithString:@"This is a pointer"]; 
[sPointer release];

My starting point was: The compiler reserves RAM memory for a pointer type and this memory (which also has an own address) contains the memory address (hexadecimal – binary) of the memory where another variable is stored (where it points to). The actual pointer would take up about 2 bytes:

1) First some general issue – not necessarily linked to objective C. The actual questions about the NSString pointer will come in point 2.
A string is a “string of characters”, where 1 character takes a fixed amount of memory space, let’s say 2 bytes.
This automatically means that the memory size occupied by a string variable is defined by the length of the character string.
Then I read this on Wikipedia:
“In modern byte-addressable computers, each address identifies a single byte of storage; data too large to be stored in a single byte may reside in multiple bytes occupying a sequence of consecutive addresses. ”
So in this case, the string value is actually contained by multiple addresses and not by a single 1 (this already differs from what I read everywhere) (?).
How are these multiple addresses contained in 1 pointer in reality? Will the pointer be divided into multiple addresses as well?
Do you know what component in a computer actually identifies and assigns the actual address “codes”?

And now my actual questions;

2) In my example, the code does 2 things:

  • It creates a pointer to the address where the string variable is stored.
  • It also actually saves the actual “String variable”: @”This is a pointer”, because otherwise there would be nothing to point to;

OK, my question; I wondered what really happens when you release the pointer [sPointer release]; are you actually releasing the pointer (containing the address), or are you also releasing the actual “string variable” from memory as well?
I have learned that when you delete the reference, the memory where the actual variable is stored will just be overwritten at the time the compiler needs memory so it does not need to be cleared at that time. Is this wrong?
If it is correct, why do they say that it’s really important to release the NSString pointer for performance reasons, if you just release the pointer which will basically contain only a few bytes? Or am I wrong, and is the memory where the actual variable is stored in fact also cleared at once with the “release” message?

And finally also: primitive datatypes are not released, but they “do” take memory space at the moment of declaration (but not more than a common pointer). Why shouldn’t we release them in fact? What prevents us from doing something like: int i = 5, followed by [i release]?;

I’m sorry – a lot of questions in 1 time! In practice, I never had problems with it, but in theory, I also really want to fully understand it – and I hope that I’m not the only one. Can we discuss the topic?
Thank you and sorry for the bother!

  • 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-25T18:41:31+00:00Added an answer on May 25, 2026 at 6:41 pm

    For the sake of the forum, I will make a brief and simplified summary of your answers as a conclusion. Thanks to all of you for this extended clarification, the mist disappeared! Don’t hesitate to react in case you want to add or rectify something:

    • Rectification: a pointer on the Mac takes 4 bytes of memory space and not 2.

    • The pointer *sPointer points to an instance of the NSString class and NOT directly to the memory where the chars are saved.
      The NSString instance consists of a set of iVars in which there is a pointer iVar that points to memory allocated where the char variables that make up the string are stored (defined when using the initWithString: instance method).

    • [sPointer release]; The release message is not sent to the pointer itself, but to the instance of the NSString Object. You are not acting on the pointer itself, but on what the pointer is pointing to (!).

    • When sending the alloc message, the retain count of the NSString instance object is increased by 1. When sending a “release” message it doesn’t mean that the concerned memory is literally being emptied, but it decreases the retain count by 1. When the retain count reaches zero, the compiler knows that the previously allocated memory is available again for re-use.

    • The way memories addresses are presented is decided by the operating system. The logical memory address used in programs is different from what the underlying implementation actually uses (physical memory address).

    • LOCAL variables (not necessarily primitive variables) are stored in the Stack memory (unlike objects instances who are stored in the Heap memory). What this means is that they will be destroyed automatically at the end of a function (they are automatically removed from the stack). More info on the memory constructs stack and heap can be found in several threads that clarify the use and difference in their own way. e.g.. What and where are the stack and heap? / http://ee.hawaii.edu/~tep/EE160/Book/chap14/subsection2.1.1.8.html

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

Sidebar

Related Questions

I'm using NSURLConnection as listed below. I have three questions about this class. When
I have seen a couple similar questions about this, however none of them work
I have a question about reference counting. This is my constructor: - (id)initWithId:(NSString *)graphId;
I have seen quite a few questions about this but cant seem to find
I have some questions about synthesized properties in Objective-C. The full list follows, but
I have some questions about using delegate patten on iPhone. This is code using
I know there's a lot of questions about this topic but I have not
i have some questions about objective-c's memory management, let's say: NSString * test= [[NSString
I have questions about System.Threading.ThreadStart Class : where can I find its specifications (
I have some questions about basic CSS that I was unable to understand or

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.