iPhone Development Tip : Debugging Memory release
28 October 2009
One Comment
I was struggling with a bug in my latest iPhone application, and frankly i got very frustrated with retain-release concept. I missed good old ( well, not that old ) garbage collector, but following code helped me a lot in understanding the release-retain cycle and getting the backtrace of whats actually going on.
First of all include following files in the code :
#include <execinfo.h> #include <stdio.h>
and then add following lines to the implementation file (.m) :
- (void)release { void* callstack[128]; int i, frames = backtrace(callstack, 128); char** strs = backtrace_symbols(callstack, frames); for (i = 0; i < frames; ++i) { printf("%s\n", strs[i]); } free(strs); NSLog(@"retainCount = %d", [self retainCount]); [super release]; }
Now, look at the console, you will see nice backtrace of release-retain cycle. Hope this helps somebody.
Related posts:
- iPhone Development Tip : Custom UINavigationBar More and more developers are creating custom user elements these...
- iPhone Dev Tip: How to find out Available/Free Memory The iPhone has limited memory,and as developer its our responsibility...
- iPhone Development Tip : How to Dynamically Initialize Class in Objective-C While working on an iPhone project i wanted a way...









[...] Continue reading here: iPhone Development Tip : Debugging Memory release | Gaurav Verma [...]