Ste*_*ott 0 iphone memory-management objective-c
我很抱歉问这么简单的问题,但这是一个我无法找到答案的具体问题.
我不是本地的Objective-c程序员,所以如果我使用任何C#术语我会道歉!
如果我在test.h中定义一个对象
@interface test : something {
NSString *_testString;
}
Run Code Online (Sandbox Code Playgroud)
然后在test.m中初始化它
-(id)init {
_testString = [[NSString alloc] initWithString:@"hello"];
}
Run Code Online (Sandbox Code Playgroud)
然后我明白我会在dealloc中释放它,因为每个init都应该有一个版本
-(void)dealloc {
[_testString release];
}
Run Code Online (Sandbox Code Playgroud)
但是,我需要澄清的是,如果在init中,我使用其中一种快捷方法创建对象,我还是会在dealloc中释放它吗?这不会破坏"一个发布一个init"规则吗?例如
-(id)init {
_testString = [NSString stringWithString:@"hello"];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
326 次 |
| 最近记录: |