假设我有:
@property(非原子,保留)NSString *foo;
在某堂课上。
我打电话:
myclass.foo = [NSString stringWithString:@"string1"]; myclass.foo = [NSString stringWithString:@"string2"];
我应该在将 [myclass.foo release] 设置为“string2”之前调用它以避免内存泄漏吗?
或者说没有任何东西再指向第一个“string1”对象就足够了?
并且在dealloc方法中[foo release]将会被调用。
最佳答案
来自Apple Docs关于声明的属性:
retain
Specifies that retain should be invoked on the object upon assignment. (The default is assign.)
The previous value is sent a release message.
关于iphone - 将 Objective-C 保留类变量设置为新对象时,是否必须对其调用release?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2706411/