Skip to content

Instantly share code, notes, and snippets.

@zbowling
Created February 17, 2011 08:12
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 zbowling/831285 to your computer and use it in GitHub Desktop.
Save zbowling/831285 to your computer and use it in GitHub Desktop.
#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];
}
@zbowling
Copy link
Author

Output format:

2011-02-17 02:01:21.125 MagicWall[25531:207] autorelease    -[MWSubmitFormController autorelease]   retainCount: 4
2011-02-17 02:01:21.126 MagicWall[25531:207] release    -[MWSubmitFormController release]   retainCount: 4
2011-02-17 02:01:21.127 MagicWall[25531:207] last called by 1   CoreFoundation                      0x018e0a6c CFRelease + 92
2011-02-17 02:01:21.127 MagicWall[25531:207] ---- call stack ----
2011-02-17 02:01:21.127 MagicWall[25531:207]  1   CoreFoundation                      0x018e0a6c CFRelease + 92
2011-02-17 02:01:21.127 MagicWall[25531:207]  2   CoreFoundation                      0x01905b8d _CFAutoreleasePoolPop + 237
2011-02-17 02:01:21.127 MagicWall[25531:207]  3   QuartzCore                          0x002cb71c _ZL23run_animation_callbacksdPv + 359
2011-02-17 02:01:21.128 MagicWall[25531:207]  4   QuartzCore                          0x002cb589 _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 157
2011-02-17 02:01:21.128 MagicWall[25531:207]  5   CoreFoundation                      0x019aafe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
2011-02-17 02:01:21.128 MagicWall[25531:207]  6   CoreFoundation                      0x019ac594 __CFRunLoopDoTimer + 1220
2011-02-17 02:01:21.128 MagicWall[25531:207] -- end call stack -- 
2011-02-17 02:01:21.128 MagicWall[25531:207]  
2011-02-17 02:01:21.129 MagicWall[25531:207] release    -[MWSubmitFormController release]   retainCount: 3
2011-02-17 02:01:21.129 MagicWall[25531:207] last called by 1   CoreFoundation                      0x018e0a6c CFRelease + 92
2011-02-17 02:01:21.129 MagicWall[25531:207] ---- call stack ----
2011-02-17 02:01:21.130 MagicWall[25531:207]  1   CoreFoundation                      0x018e0a6c CFRelease + 92
2011-02-17 02:01:21.130 MagicWall[25531:207]  2   CoreFoundation                      0x01905b8d _CFAutoreleasePoolPop + 237
2011-02-17 02:01:21.130 MagicWall[25531:207]  3   QuartzCore                          0x002cb71c _ZL23run_animation_callbacksdPv + 359
2011-02-17 02:01:21.130 MagicWall[25531:207]  4   QuartzCore                          0x002cb589 _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 157
2011-02-17 02:01:21.130 MagicWall[25531:207]  5   CoreFoundation                      0x019aafe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
2011-02-17 02:01:21.131 MagicWall[25531:207]  6   CoreFoundation                      0x019ac594 __CFRunLoopDoTimer + 1220
2011-02-17 02:01:21.131 MagicWall[25531:207] -- end call stack -- 
2011-02-17 02:01:21.131 MagicWall[25531:207]  
2011-02-17 02:01:21.131 MagicWall[25531:207] release    -[MWSubmitFormController release]   retainCount: 2
2011-02-17 02:01:21.132 MagicWall[25531:207] last called by 1   CoreFoundation                      0x018e0a6c CFRelease + 92
2011-02-17 02:01:21.132 MagicWall[25531:207] ---- call stack ----
2011-02-17 02:01:21.133 MagicWall[25531:207]  1   CoreFoundation                      0x018e0a6c CFRelease + 92
2011-02-17 02:01:21.133 MagicWall[25531:207]  2   CoreFoundation                      0x01905b8d _CFAutoreleasePoolPop + 237
2011-02-17 02:01:21.133 MagicWall[25531:207]  3   QuartzCore                          0x002cb71c _ZL23run_animation_callbacksdPv + 359
2011-02-17 02:01:21.133 MagicWall[25531:207]  4   QuartzCore                          0x002cb589 _ZN2CAL14timer_callbackEP16__CFRunLoopTimerPv + 157
2011-02-17 02:01:21.134 MagicWall[25531:207]  5   CoreFoundation                      0x019aafe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
2011-02-17 02:01:21.134 MagicWall[25531:207]  6   CoreFoundation                      0x019ac594 __CFRunLoopDoTimer + 1220
2011-02-17 02:01:21.134 MagicWall[25531:207] -- end call stack -- 
2011-02-17 02:01:21.134 MagicWall[25531:207]  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment