Alex,

What your three lines of code do:

> NSString *myString;

Compiler allocates space for a pointer on the run time stack.

> myString = @"Hi";

Compiler creates an NSString object somewhere in the heap with the value @"Hi" 
and points the pointer to it.

> myString = @"Hi there";

Compiler creates another NSString object somewhere else in the heap with the 
value @"Hi there" and points the pointer to it. Depending on the type of memory 
management you are using the first string might leak since there is nothing 
pointing to it any more. If you are using ARC the compiler will insert a call 
to release to remove the first string.

There is nothing in your code that tries to mutate a string. All it does is 
create two different strings.

Tom Wetmore
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to