【发布时间】:2011-06-29 10:22:01
【问题描述】:
我是内存管理的新手,我搜索过类似的主题,但没有找到导致内存泄漏的简单示例。我正在使用 Instruments 测试我的应用程序,它说我在 pushViewController 中有 144 字节的内存泄漏。
rootViewController:
- (IBAction)optionsAction
{
optionsViewController *ovc = [[optionsViewController alloc] init];
// MEMORY LEAK 100.0%
[self.navigationController pushViewController:ovc animated:YES];
[ovc release];
}
optionsViewController.h
@interface optionsViewController : UIViewController <ADBannerViewDelegate> {
UISlider *volumeSlider;
UISwitch *soundSwitch;
SystemSoundID SSID;
}
@property (nonatomic, retain) IBOutlet UISwitch *soundSwitch;
@property (nonatomic, retain) IBOutlet UISlider *volumeSlider;
@property (assign) SystemSoundID SSID;
@end
optionsViewController.m
- (void)dealloc
{
[volumeSlider release];
[soundSwitch release];
AudioServicesDisposeSystemSoundID(self.SSID);
[super dealloc];
}
您知道这次泄漏的原因是什么吗?你能说我应该在哪里搜索问题,rootViewController还是optionsViewController?
【问题讨论】:
-
检查
initoptionsViewController控制器的功能。 -
初始化是默认的:- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // 自定义初始化 } return self; }
标签: iphone uiviewcontroller memory-leaks