Created
February 17, 2011 08:12
-
-
Save zbowling/831285 to your computer and use it in GitHub Desktop.
This file contains 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 RETAINSTACKLENGTH 7 | |
#define RETAINLOG(action) NSLog(@"%@ \t%s \tretainCount: %i", action, __PRETTY_FUNCTION__, [self retainCount]) | |
#define RETAINCOUNTSTACK(action) { \ | |
RETAINLOG(action); \ | |
NSArray *stack = [NSThread callStackSymbols]; \ | |
NSLog(@"last called by %@", [stack objectAtIndex: 1]); \ | |
int max = [stack count] < RETAINSTACKLENGTH ? [stack count] : RETAINSTACKLENGTH; \ | |
NSLog(@"---- call stack ----"); \ | |
for (int i = 1; i < max; i++) { \ | |
NSLog(@" %@", [stack objectAtIndex: i]); \ | |
} \ | |
NSLog(@"-- end call stack -- "); \ | |
NSLog(@" "); \ | |
} | |
- (id)retain { | |
RETAINCOUNTSTACK(@"retain"); | |
return [super retain]; | |
} | |
- (void)release { | |
RETAINCOUNTSTACK(@"release"); | |
[super release]; | |
} | |
- (id)autorelease { | |
RETAINLOG(@"autorelease"); | |
return [super autorelease]; | |
} | |
- (void)dealloc { | |
RETAINLOG(@"dealloc"); | |
... | |
[super dealloc]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output format: