【发布时间】:2010-09-09 18:23:47
【问题描述】:
我对objective-c的内存管理有一些疑问,
比方说:
NSString * test= [[NSString alloc] init ]
test=@"msg";
[object setStr1: test ]; // declared as: @property(copy, readwrite)
[object setStr2: test ]; // declared as: @property(retain, readwrite)
[object setStr3: test ]; // declared as: @property(assign, readwrite)
test=@"some other string"
我认为str1 会有一份tests 内容的副本:str1 将指向包含msg 的内存(堆)的一个地址,这个地址与test 指向的地址不同.对吧?
关于str2:
1.它存储什么?,我猜指向test的地址相同,但它会将test的引用计数器增加到2。
2.当我改变测试的内容时,str2有什么?我猜它仍然指向msg
关于str3:不正确,对吧?assign 是做什么的?
谢谢。
额外问题:
NSString * test= [[NSString alloc] init ]
test=@"msg";
test=@"something";
我应该在更改内容之前发布测试吗?
【问题讨论】:
标签: objective-c objective-c++ objective-c-runtime