Reputation: 3713
I apologise if this a silly question but I'm very new to iOS development. So here is the question:
when I add the SecondView
to the FirstView
, the memory is allocated but when I remove it, not all of the allocated memory are released.
Here's the code:
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
Here are some numbers I got from Instruments (Live Bytes):
Note: Instruments shows no leak
Shouldn't the Live bytes become the initial value (671 KB)? instead of 809 KB, what is left over?
Upvotes: 0
Views: 82
Reputation: 17186
This is not leak. Apple caches some of the details. First time when you load viewcontroller, it will increase the memory usage. Once you dealloc it, some of the things will remain cached.
So, first readings will not give you exact picture.
Carry the same exercise for 2-3 times. So, you should able to have same memory utilization at the start of 3rd iteration and at the end of 3rd iteration.
If it increases at each cycle, then there might be a case of memory leak.
Upvotes: 1