autorelease

来源:互联网 发布:mac小游戏推荐 编辑:程序博客网 时间:2024/05/01 12:55

Problem Cases 


- (NSString *)fullName { 

NSString *result; 

result = [[NSString alloc] initWithFormat:@”%@ %@”, 

  firstName, lastName]; 

return result; 

} 

[result autorelease]; 

 


Just right:  result is released, but not immediately 

Caller gets valid object and could retain if needed

原创粉丝点击