|
30 | 30 |
|
31 | 31 | #import <objc/runtime.h>
|
32 | 32 | static NSMutableDictionary *gScrollViewListeners;
|
| 33 | +static NSMutableDictionary *gScrollViewDealloc; |
33 | 34 |
|
34 | 35 | @implementation NSObject (SPObjectAdditions)
|
35 | 36 |
|
@@ -97,7 +98,10 @@ - (void)_scrollViewDidChangeBounds:(id)obj
|
97 | 98 |
|
98 | 99 | NSString *key = [NSString stringWithFormat:@"snd=%p,obs=%p",obj,self];
|
99 | 100 |
|
100 |
| - [msg appendFormat:@"registration info for pair (%@):\n %@",key,[gScrollViewListeners objectForKey:key]]; |
| 101 | + [msg appendFormat:@"registration info for pair (%@):\n %@\n\n",key,[gScrollViewListeners objectForKey:key]]; |
| 102 | + |
| 103 | + NSString *deallocKey = [NSString stringWithFormat:@"=%p",self]; |
| 104 | + [msg appendFormat:@"self %@ was originally dealloc'ed at:\n %@",deallocKey,[gScrollViewDealloc objectForKey:deallocKey]]; |
101 | 105 |
|
102 | 106 | @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:msg userInfo:nil];
|
103 | 107 | }
|
@@ -144,4 +148,41 @@ - (void)sp_addObserver:(id)notificationObserver selector:(SEL)notificationSelect
|
144 | 148 | [self sp_addObserver:notificationObserver selector:notificationSelector name:notificationName object:notificationSender];
|
145 | 149 | }
|
146 | 150 |
|
| 151 | +@end |
| 152 | + |
| 153 | +#import "SPTableView.h" |
| 154 | + |
| 155 | +@implementation SPTableView (SPScrollViewDebug) |
| 156 | + |
| 157 | ++ (void)load |
| 158 | +{ |
| 159 | + static dispatch_once_t onceToken; |
| 160 | + |
| 161 | + dispatch_once(&onceToken, ^{ |
| 162 | + gScrollViewDealloc = [[NSMutableDictionary alloc] init]; |
| 163 | + |
| 164 | + Class tableView = [self class]; |
| 165 | + |
| 166 | + SEL orig = @selector(dealloc); |
| 167 | + SEL exch = @selector(sp_dealloc); |
| 168 | + |
| 169 | + Method origM = class_getInstanceMethod(tableView, orig); |
| 170 | + Method exchM = class_getInstanceMethod(tableView, exch); |
| 171 | + |
| 172 | + method_exchangeImplementations(origM, exchM); |
| 173 | + }); |
| 174 | +} |
| 175 | + |
| 176 | +- (void)sp_dealloc |
| 177 | +{ |
| 178 | + NSString *key = [NSString stringWithFormat:@"=%p",self]; |
| 179 | + NSString *val = [NSString stringWithFormat:@"\ndealloc backtrace:\n%@\n\n",[NSThread callStackSymbols]]; |
| 180 | + |
| 181 | + [gScrollViewDealloc setObject:val forKey:key]; |
| 182 | + |
| 183 | + // not recursive! method is swizzled. |
| 184 | + [self sp_dealloc]; |
| 185 | +} |
| 186 | + |
| 187 | + |
147 | 188 | @end
|
0 commit comments