-
@implementation SecondViewController
-
- (void)setTest1:(NSString *)test//retain
-
{
-
// test需要先retain一次,放在自赋值时test被释放为nil
-
[test retain];
-
if (_test1 != nil) {
-
[_test1 release];
-
}
-
//直接release无需判断也是可以的,iOS中对nil进行release操作合法
-
//[_test1 release];
-
_test1 = test;
-
}
-
- (void)setTest2:(NSString *)test//copy
-
{
-
if (_test2 != nil) {
-
[_test2 release];
-
}
-
// 也可以不用判断
-
// [_test2 release];
-
_test2 = [test copy];
-
}
retain 和release 的区别
最新推荐文章于 2024-06-22 22:09:48 发布