Skip to content

Instantly share code, notes, and snippets.

@reflog
Created May 26, 2011 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reflog/993164 to your computer and use it in GitHub Desktop.
Save reflog/993164 to your computer and use it in GitHub Desktop.
template for tracking allocations
#define SYNTESIZE_TRACE(X) \
@interface Trace##X : X { \
} \
@end \
\
@implementation Trace##X\
\
- (id)retain {\
NSUInteger oldRetainCount = [super retainCount];\
id result = [super retain];\
NSUInteger newRetainCount = [super retainCount];\
NSLog(@"%@<%@> ++retainCount: %d => %d\n", [self class] , self, oldRetainCount, newRetainCount);\
NSLog(@"%@\n", [NSThread callStackSymbols] );\
return result;\
}\
\
- (void)release {\
NSUInteger oldRetainCount = [super retainCount];\
BOOL gonnaDealloc = oldRetainCount == 1;\
if (gonnaDealloc) {\
NSLog(@"%@<%@> --retainCount: 1 => 0 (gonna dealloc)\n", [self class] , self);\
NSLog(@"%@\n", [NSThread callStackSymbols] );\
}\
[super release];\
if (!gonnaDealloc) {\
NSUInteger newRetainCount = [super retainCount];\
NSLog(@"%@<%@> --retainCount: %d => %d\n", [self class] , self, oldRetainCount, newRetainCount);\
NSLog(@"%@\n", [NSThread callStackSymbols] );\
}\
}\
\
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment