我对xCode 4.3内存泄漏仪器有一个非常奇怪的问题......基本上它在以下情况下不起作用......
所以这里是PROBLEMATIC类的代码
@interface LeakTestView : UIView
- (id)initWithFrame:(CGRect)frame;
@end
@implementation LeakTestView
- (id)initWithFrame:(CGRect)frame
{
NSLog(@"initWithFrame called");
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
现在我创造了泄漏......
- (IBAction)leak:(id)sender {
LeakTestView* leak=[[LeakTestView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
NSLog(@"class is %@", [leak class]);
}
Run Code Online (Sandbox Code Playgroud)
所以问题是这个泄漏不会被发现......
如果我将基类更改为NSObject而不是initWithFrame重写init(请参阅下面的内容),那么将检测到泄漏....
所以这里是将被检测到的泄漏代码
@interface LeakTestView : NSObject
- (id) init;
@end
@implementation LeakTestView
- (id) init {
NSLog(@"init called");
self = [super init];
if (self) {
}
return self; …Run Code Online (Sandbox Code Playgroud) xcode memory-leaks ios xcode-instruments automatic-ref-counting