2
NSString * str1 = @"haha";
NSString * str2 = [str1 copy];
str1 = @"laa";
NSLog(@"str1的地址为:%p", str1);
NSLog(@"str2的地址为:%p", str2);
NSLog(@"str1的值为:%@", str1);
NSLog(@"str2的值为:%@", str2);
作为上面的代码,它们的内存地址是不同的。但如果我删除第三行,他们的内存地址是相同的。你能告诉我原因吗?我已经搜索了很长时间,谢谢为什么nstring obj的内存地址与iOS中的复制的地址不同?
已经给出了答案在这个环节。可能会帮助你.. https://stackoverflow.com/questions/7376261/are-nsstrings-stored-on-the-heap-or-on-the-stack-and-what-is-a-good-way-到initi –