Skip to content

Commit aa192cf

Browse files
committed
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.
1 parent 4707c32 commit aa192cf

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

Source/SPObjectAdditions.m

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#import <objc/runtime.h>
3232
static NSMutableDictionary *gScrollViewListeners;
33+
static NSMutableDictionary *gScrollViewDealloc;
3334

3435
@implementation NSObject (SPObjectAdditions)
3536

@@ -97,7 +98,10 @@ - (void)_scrollViewDidChangeBounds:(id)obj
9798

9899
NSString *key = [NSString stringWithFormat:@"snd=%p,obs=%p",obj,self];
99100

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]];
101105

102106
@throw [NSException exceptionWithName:NSInternalInconsistencyException reason:msg userInfo:nil];
103107
}
@@ -144,4 +148,41 @@ - (void)sp_addObserver:(id)notificationObserver selector:(SEL)notificationSelect
144148
[self sp_addObserver:notificationObserver selector:notificationSelector name:notificationName object:notificationSender];
145149
}
146150

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+
147188
@end

Source/SPTableView.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ - (id) init
6161
return self;
6262
}
6363

64+
- (void)dealloc
65+
{
66+
[super dealloc];
67+
}
68+
6469
- (void) awakeFromNib
6570
{
6671
[super setDoubleAction:@selector(_doubleClickAction)];

0 commit comments

Comments
 (0)