【发布时间】:2015-06-20 10:16:00
【问题描述】:
今天我用NSStrings 测试了一个。可悲的是,当我运行此代码时,我遇到了严重的内存泄漏(xcode 仪器向我展示了这一点):
- (IBAction)start:(id)sender {
while (true) // Yes I know that this is an infinity loop
{
NSString *test = [[NSString alloc] init];
test = [NSString stringWithFormat:@"llalalallalalallalalalalallalalllallalalallalal"];
test = nil;
// Why does this leak memory ? I think ARC is releasing it automatically ?
}
}
这是仪器的截图:
能否请我帮助我理解为什么此代码泄漏(ARC 已开启)?
【问题讨论】:
标签: objective-c macos memory-leaks nsstring automatic-ref-counting