使用 addSubview 时防止内存泄漏的正确方法是什么?我收到 Instruments 的投诉,称此代码存在泄漏。我究竟做错了什么?
示例代码:
我的.h
@interface MyCustomControl : UIControl {
UILabel *ivarLabel;
}
@property (nonatomic, retain) UILabel *ivarLabel;
我的
@synthesize ivarLabel;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
self.ivarLabel = [[UILabel alloc] initWithFrame:CGRectMake( 0, 0, 10, 10)];
[self addSubview:self.ivarLabel];
}
return self;
}
- (void)dealloc {
[ivarLabel release];
[super dealloc];
}
谢谢你的帮助。