NSString and NSMutableString memory issues

I am trying to wrap my head around NSString and NSMutableString and how they affect memory.

In my research, I came to the conclusion that if I create an NSString object and give it a value, change the value later, the original object will be replaced with another with a new value.

My question is changing the value of NSString. When the NSString value changes and the object pointed to is replaced with a new object, what happens to the original object? Is it a memory leak?

Thank! AT

+3
source share
2 answers

The original NSStringwill be released by the system and therefore will not cause a leak.

+1
source

NSString , , .

, . NSString

NSString *myString = @"string1";

myString = @"string2";

.

. NSString ,

NSString *myString = [NSString stringWithFormat:@"String %d", 1];

NSString, myString.

myString = [NSString stringWithFormat:@"String %d", 2];

NSString, . .

ARC, NSString, , , . , .

, , - - , .

, , . , . (), ARC.

, , , NSString - (int, boolean, float ..), , , . , , .

+2

All Articles