From aa192cfe24c2866554d8785152e045f42233f287 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 14 Sep 2015 03:28:54 +0200 Subject: Even more debug code for _scrollViewDidChangeBounds Since SPTableView and SPCopyTable seem to be the cause behind the majority of crashes let's take a closer look at them. --- Source/SPObjectAdditions.m | 43 ++++++++++++++++++++++++++++++++++++++++++- Source/SPTableView.m | 5 +++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Source/SPObjectAdditions.m b/Source/SPObjectAdditions.m index 55e95437..9f51d652 100644 --- a/Source/SPObjectAdditions.m +++ b/Source/SPObjectAdditions.m @@ -30,6 +30,7 @@ #import static NSMutableDictionary *gScrollViewListeners; +static NSMutableDictionary *gScrollViewDealloc; @implementation NSObject (SPObjectAdditions) @@ -97,7 +98,10 @@ retryDescribe: NSString *key = [NSString stringWithFormat:@"snd=%p,obs=%p",obj,self]; - [msg appendFormat:@"registration info for pair (%@):\n %@",key,[gScrollViewListeners objectForKey:key]]; + [msg appendFormat:@"registration info for pair (%@):\n %@\n\n",key,[gScrollViewListeners objectForKey:key]]; + + NSString *deallocKey = [NSString stringWithFormat:@"=%p",self]; + [msg appendFormat:@"self %@ was originally dealloc'ed at:\n %@",deallocKey,[gScrollViewDealloc objectForKey:deallocKey]]; @throw [NSException exceptionWithName:NSInternalInconsistencyException reason:msg userInfo:nil]; } @@ -144,4 +148,41 @@ retryDescribe: [self sp_addObserver:notificationObserver selector:notificationSelector name:notificationName object:notificationSender]; } +@end + +#import "SPTableView.h" + +@implementation SPTableView (SPScrollViewDebug) + ++ (void)load +{ + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + gScrollViewDealloc = [[NSMutableDictionary alloc] init]; + + Class tableView = [self class]; + + SEL orig = @selector(dealloc); + SEL exch = @selector(sp_dealloc); + + Method origM = class_getInstanceMethod(tableView, orig); + Method exchM = class_getInstanceMethod(tableView, exch); + + method_exchangeImplementations(origM, exchM); + }); +} + +- (void)sp_dealloc +{ + NSString *key = [NSString stringWithFormat:@"=%p",self]; + NSString *val = [NSString stringWithFormat:@"\ndealloc backtrace:\n%@\n\n",[NSThread callStackSymbols]]; + + [gScrollViewDealloc setObject:val forKey:key]; + + // not recursive! method is swizzled. + [self sp_dealloc]; +} + + @end diff --git a/Source/SPTableView.m b/Source/SPTableView.m index 72535038..7a1c01c1 100644 --- a/Source/SPTableView.m +++ b/Source/SPTableView.m @@ -61,6 +61,11 @@ return self; } +- (void)dealloc +{ + [super dealloc]; +} + - (void) awakeFromNib { [super setDoubleAction:@selector(_doubleClickAction)]; -- cgit v1.2.3