I’m diving into iOS development and am getting familiar with the tools. At the end of every day, I perform a “Run with instruments tool -> Leaks” on my app to check for any memory leaks I may have implemented that day. It rarely seems to detect any leaks and, while I’d like to think I’m just a natural iOS programmer, I refuse to believe that 😉
Anyhow, I just found what I think is a memory leak in my code and it doesn’t get caught by Instruments. I have this line of code…
gkSession = [[GKSession alloc] initWithSessionID:@"testID" displayName:@"Temp Display Name" sessionMode:GKSessionModeClient];
and I found that I wasn’t calling release anywhere in my code. My questions are…
- Is this a memory leak?
- If so, what are some reasons that Instruments might not catch it?
My obvious concern is that I have memory leaks in my code and Instruments isn’t catching them.
Thanks so much in advance for your help!
There are multiple types of dynamically allocated memory.
Memory with a reference count
greater than zero which is still referenced and is in use.
Memory with a reference count
of zero which is still referenced and is still in use.
Memory with a reference count greater than zero which is not referenced.
Memory with a reference count of zero which is not referenced.
Memory with a reference count
greater than zero which is still referenced and is NOT in use.
Type one is normal in use memory. Type two is a bug that will be reported as an illegal access when you try to follow the reference. Type 3 is the type of leak that instruments detects. Type 4 should be freed by the memory system.
Type 5 is a leak which cannot be detected by instruments, and will also not be handled by a full garbage collector. This is what you seem to have.
EDIT:
I forgot type 6 — Memory with a reference count that doesn’t match the number of actual references. This will probably eventually turn into type 2 or 4.