-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYDeallocDetector.m
61 lines (48 loc) · 1.46 KB
/
SSYDeallocDetector.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#import "SSYDeallocDetector.h"
@implementation SSYDeallocDetector
#if 0
#warning Logging retains, releases and deallocs of Dealloc Detector
#define LOG_RETAINS_RELEASES_AND_DEALLOCS 1
#endif
#if LOG_RETAINS_RELEASES_AND_DEALLOCS
- (id)retain {
NSLog(@"75133: Retained SSYDeallocDetector %p", (__bridge void*)self) ;
return [super retain] ;
}
- (oneway void)release {
NSLog(@"75143: Released SSYDeallocDetector %p", (__bridge void*)self) ;
[super release] ;
}
#endif
- (void)dealloc {
[_invocation invoke] ;
[_invocation release] ;
#if LOG_RETAINS_RELEASES_AND_DEALLOCS
NSLog(@"75153 Deallocced %p", (__bridge void*)self) ;
#else
if (_logMsg) {
NSLog(@"Deallocced %p %@", (__bridge void*)self, _logMsg) ;
}
#endif
[_logMsg release] ;
[super dealloc] ;
}
- (id)initWithInvocation:(NSInvocation*)invocation
logMsg:(NSString*)logMsg {
self = [super init] ;
if (self) {
[self setInvocation:invocation] ;
[self setLogMsg:logMsg] ;
if (logMsg) {
NSLog(@"Created %p %@", (__bridge void*)self, logMsg) ;
}
}
return self ;
}
+ (SSYDeallocDetector*)detectorWithInvocation:(NSInvocation*)invocation
logMsg:(NSString*)logMsg {
SSYDeallocDetector* instance = [[SSYDeallocDetector alloc] initWithInvocation:invocation
logMsg:logMsg] ;
return [instance autorelease] ;
}
@end