Created
May 26, 2011 13:41
-
-
Save reflog/993164 to your computer and use it in GitHub Desktop.
template for tracking allocations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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