Widgets Constant String vs. Immutable Strings
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 01, 2015, 02:13:45 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Old Stuff
| |-+ Chapter Study
| | |-+ Chapter 17 - Memory Management
| | | |-+ Constant String vs. Immutable Strings
Pages: [1] Go Down
Author Topic: Constant String vs. Immutable Strings (Read 1932 times)
Full Member
Posts: 169

WWW Email

on: July 22, 2009, 09:00:25 PM

I thought constant strings and immutable strings were the same but after looking at Program 17.2 I am questioning myself.

If I create a string in the following ways what is the difference if any?

Code: (Objective-C)
NSString *myString1 = @"This is my string";
NSString *myString2 = [NSString stringWithString: @"This is also my string"];

Further more the note on page 411 says the system is clever and realizes the immutable string object is being initialized by a constant string object. What other objects can an immutable string be initialized with?


Last Edit: July 22, 2009, 09:06:07 PM by jonthornham Logged

Jon Thornham

Hero Member
Posts: 3114

Reply #1 on: July 22, 2009, 09:11:40 PM

There really is no difference.   myString1 and myString2 will both reference a constant string object that has been created at compile time and that will have a reference count of 0xffffffff (or as noted in the text, on some systems, 0x7fffffff).

An immutable string object can be initialized from another immutable string object (either through a variable reference or constant string object) or from a mutable string object.


Steve Kochan
Full Member
Posts: 169

WWW Email

Reply #2 on: July 25, 2009, 11:46:46 AM

Thanks Steve.

Jon Thornham

Pages: [1] Go Up
Jump to:

Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 All rights reserved.