bea*_*ain 14 cocoa memory-management objective-c automatic-ref-counting
在ARC,它创建一个内存泄漏到alloc
成@property (strong)
// MyClass.h
@property (strong) NSString *myString;
// MyClass.m
@synthesize myString=_myString;
- (void)viewDidLoad
{
self.myString = [[NSString alloc] initWithFormat:@"Test %@", otherString];
}
Run Code Online (Sandbox Code Playgroud)
我知道在手动内存管理中,等效会造成泄漏
// MyClass.h
@property (retain) NSString *myString;
// MyClass.m
@synthesize myString=_myString;
- (void)viewDidLoad
{
self.myString = [[NSString alloc] initWithFormat:@"Test %@", otherString];
}
- (void)dealloc
{
[_myString release];
}
Run Code Online (Sandbox Code Playgroud)
ARC能否正确处理顶级示例?它是否优化了其中一个保留?或者也许在dealloc中发布两次?
Jos*_*erg 16
这在ARC下完全有效.
我建议您阅读ARC文档,以便更加信任它所提供的功能.http://clang.llvm.org/docs/AutomaticReferenceCounting.html和Mike Ash有一篇很棒的博客文章,关于它如何运作http://www.mikeash.com/pyblog/friday-qa-2011-09-30-automatic -reference-counting.html
归档时间: |
|
查看次数: |
3173 次 |
最近记录: |