如果这是一个愚蠢的问题,我深表歉意,但我对 iOS 开发非常陌生。所以这是一个问题:
当我添加SecondView
到 时FirstView
,分配了内存,但是当我删除它时,并非所有分配的内存都被释放。
这是代码:
第一视图:
@interface FirstView : UIViewController
@property (nonatomic, retain) SecondView *secondView;
- (IBAction)loadSecondView;
@end
@implementation ViewController
@synthesize editView;
- (IBAction)loadSecondView{
secondView = [[SecondView alloc]init];
[self presentModalViewController:editView animated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
[secondView release]; secondView = nil; //this is called after SecondView is removed
}
第二视图:
@interface SecondView : UIViewController
@end
@implementation EditView
-(void)viewDidLoad{
for (int intCounter = 0; intCounter < 10000; intCounter++){
UIImageView *image = [[UIImageView alloc]init]; //create 10000 images just to fill up the memory
[self.view addSubview:image];
[image release]; image = nil;
}
}
@end
以下是我从 Instruments (Live Bytes) 获得的一些数字:
- 已加载的 FirstView:671 KB
- 加载的第二视图:3.28 MB
- 已删除 SecondView:809 KB
注意:仪器显示没有泄漏
Live 字节不应该成为初始值(671 KB)吗?剩下的不是 809 KB,还有什么?