Im using Storyboards in my app and I have noticed the following. View Controller A is the root VC, pushes View Controller B, who then presents modally VCC. I have an unwind segue from VCC to VCA when the user presses a button. Putting logs on the dealloc method of VCB and VCC y see that they are called when the unwind segue occurs, so that's fine. However none of the memory allocated is freed at that moment. Is this a normal behavior, where the memory is not freed instantly but rather later?
2 Answers
Found the answer to my own question. Through view controllers B and C I'm using a bunch of images, and I've loaded those with
[UIImage imageNamed:@"imageName"];
which caches all the images I've used for faster reloading them later, therefore not releasing that memory when the view controllers are deallocated.
The other option is to use
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"imageName" ofType:@"png"]];
which doesn't caches the images and all the memory is then released upon deallocation. But I'm going to roll with the first option since I will be using these images frequently through the app.
This post was useful https://stackoverflow.com/a/17569993/5009180
I see 2 possibilities here:
You aren't calling [super dealloc] all the way up to NSObject, so the memory is never freed. (In non-ARC code, you should always call [super dealloc] at the end of every dealloc you write.)
You are running with NSZombies enabled, so the memory isn't actually freed when dealloc is called.

- 488
- 4
- 9
-
1. I never call dealloc, Im using ARC and calls to dealloc are forbidden. Dealloc is called automatically, I just put a log inside the method to know if it is being called or not. As for the second part, I'm not actually using Instruments, I'm just monitoring the memory behavior on the memory report of the debug navigator. – Oscar Oct 24 '15 at 16:07
-
1. Correct, even without ARC, you don't call dealloc yourself. However, if you wrote dealloc yourself you always want to ensure you call super from your dealloc implementation. (If you don't, you are overriding your superclass' implementations of dealloc, which will lead to leaks.) 2. NSZombies can be enabled without using instruments. However, I see neither of these was the issue in your case. – Sam Falconer Oct 24 '15 at 18:01
-
EDIT: Yes, in ARC, you would not call super in dealloc. – Sam Falconer Oct 24 '15 at 18:09