【发布时间】:2011-06-21 03:33:19
【问题描述】:
大家好,我在以下示例中理解保留的概念时遇到了问题。我知道保留的用法......但在这里感到困惑..
我有 2 个类 View1 和 View2
here is method of View1
-(IBAction)callingView2
{
view2 *view=[[view2 alloc] init];
[self.navigationController pushViewController:view animated:YES];
NSString *ss=[[NSString alloc]initWithString:@"Hi friend"];
[view callingToRetain:ss];
[ss release];
[view release];
}
在 view2 中我有 2 个方法,str 是一个字符串(未分配)
-(void)callingToRetain:(NSString*)s
{
//[s retain]; //it is not effecting my program
str = s;
}
//And then printing it on a button click after reaching to view2
-(IBAction)print
{
NSLog(@"string = %@",str);
}
规则说如果我以后必须使用它,我应该保留字符串,但在这里它在没有保留的情况下工作.....
我认为这是由于str = s;,因为它保留到 MAX_VALUE,但我不确定...
如果这是问题所在,那么它会影响内存泄漏的概念吗?
有什么建议吗?
【问题讨论】:
标签: iphone objective-c memory-management memory-leaks retain