我很抱歉如果这个愚蠢的问题但我很新的iOS开发。所以这里是问题:视图没有完全释放
当我将SecondView
添加到FirstView
,内存分配,但是当我删除它时,并非所有分配的内存被释放。
下面的代码:
的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
}
SecondView:
@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
这里有一些数字,我从仪器得到(直播字节):
- 的firstView加载:671 KB
- SecondView加载:3.28 MB
- SecondView移除:809 KB
注:仪器显示没有泄漏
不该实时字节成为初始值(671 KB)?而不是809 KB,剩下的是什么?
你为什么不使用弧?如果你这样做,你不必担心发布的东西。 (只设置指针为零,操作系统将负责其余部分) – Pochi 2012-08-08 09:01:46
我刚把项目移植到了arc,仍然有同样的问题。 – user945711 2012-08-08 09:05:52
有什么问题?没有泄漏意味着它是好的。一些内存可能用于缓存,单身等,只要你的程序没有泄漏,并没有因内存不足而崩溃,没有必要弄清楚这个低级别发生了什么 – 2012-08-08 09:29:05