Reputation: 2288
I have a UIViewController A, in this point my memory its 104 Mb. In A, I open UIVIewController B normally like this:
UIViewController *b = [[UIViewController alloc] initWithLevel:level actualUser:actualUser parentViewController:self];
[self presentViewController:b animated:NO completion:nil];
At this point my memory its 132 Mb, then when the user touch a button i open UIViewController C like this:
UIViewController *c = [[UIViewController alloc] initWithBlackboard:3];
[self dismissViewControllerAnimated:NO completion:^{
[parentViewController(i get this property in the init method) presentViewController:c animated:NO completion:nil];
}];
Here, what I do, is close B and then open C, so when I close C it leads me directly to A.
At this point my memory its a 153 Mb, which is wrong, because the memory of B never deallocates (frees). After this, I dismiss like this to return to A:
[self.presentingViewController dismissViewControllerAnimated:NO completion:^{}];
And instead of having 104 Mb I have 132 Mb, so B was never released. The windows are opened and closed in the right way but the memory it's the problem.
I have tested each UIViewController separately and I didn't have any memory issues. The problem comes when they are bound together. Any ideas?
I have also looked out for memory leaks, and I haven't found any.
Upvotes: 3
Views: 2217
Reputation: 2288
The problem was an id variable that i never "release" set to nil
Upvotes: 0
Reputation: 514
It's a circular reference.
@interface A : UIViewController {
UIViewController* B;
}
@end
@interface B : UIViewController {
UIViewController* A;
}
@end
and if you use ARC with strong references or default,It makes memory leak..
The memory tool Instruments not always correct.In some Complex programs,To Log the retain count is a way to Check whether release correct.If you use ARC to manage memory,It is best to avoid circular reference.
This link is office ARC document,It is very detailed. enter link description here
Just a little suggest.Best wishes!
Upvotes: 4