由于某些原因,使用loadNibNamed:会导致内存泄漏。
假设我有这样的接口:
@interface Step : UIViewController
{
IBOutlet UIView *keyPadPopupView;
}
@property (nonatomic, assign) IBOutlet UIView *keyPadPopupView;在步骤中:
@synthesize keyPadPopupView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]))
{
[[NSBundle mainBundle] loadNibNamed:@"customNumberKeypad" owner:self options:nil];
[self.view addSubview:keyPadPopupView];
[keyPadPopupView release];
}
return self;
}
- (void) dealloc
{
NSLog(@"dealloc........%@", [self class]);
[super dealloc];
}我使用以下命令执行初始化:
Step *step = [[Step alloc] initWithNibName:@"StepXib" bundle:nil];
[step release]; 我似乎不明白为什么dealloc方法从来没有被调用过。在Xib中,文件的所有者是Step,而keyPadPopupView连接在IB中。
我是不是漏掉了什么?
谢谢!
发布于 2011-06-20 09:02:26
在iOS中,连接IBOutlet会导致对象被保留(与OS X不同)。将视图添加到子视图会导致保留该视图。所以..。
从nib加载- +1 (1)
添加为子视图- +1 (2)
版本- -1 (1)
你仍然有出色的留住。
是否正在调用viewDidUnload?通常情况下,您会在其中释放所有保留的子视图。
https://stackoverflow.com/questions/3401847
复制相似问题