2

I'm seeing a crash in UIScrollView because the delegate was released from memory before the scrollView has finished an animation.

I know this to be the cause, and the solution should be to manually nil out the delegate of the UIScrollView when the delegate hits its own dealloc call. I've done this to every viewController that I can find which has a UIScrollView subview, but the crash still persists. I know the root cause is that UIScrollView's delegate is assign instead of weak, and I'm curious if I can override this somehow (through a category?).

Is there another solution?

Here's the dump of the crash, I find it curious that one of the calls on the stack references UITextView (which inherits from UIScrollView), could this offer up a clue to the location of the offending UIScrollView?

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0xc1a9e521
0 libobjc.A.dylib objc_msgSend + 5 respondsToSelector:
1 UIKit  -[UIScrollView(UIScrollViewInternal) _delegateScrollViewAnimationEnded] + 52
2 UIKit  -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded:finished:] + 184
3 UIKit  -[UITextView _scrollViewAnimationEnded:finished:] + 306
4 UIKit  -[UIAnimator stopAnimation:] + 476
5 UIKit  -[UIAnimator(Static) _advanceAnimationsOfType:withTimestamp:] + 304
6 UIKit  -[UIAnimator(Static) _LCDHeartbeatCallback:] + 52
7 QuartzCore CA::Display::DisplayLinkItem::dispatch() + 98
8 QuartzCore CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 366
9 IOMobileFramebuffer IOMobileFramebufferVsyncNotifyFunc + 90
10 IOKit IODispatchCalloutFromCFMessage + 256
11 CoreFoundation __CFMachPortPerform + 132
18 UIKit    UIApplicationMain + 1440
Jimmy Xu
  • 689
  • 1
  • 5
  • 14
  • set scrollView.delegate = nil when object is about to dealloc – Adnan Aftab Aug 19 '15 at 17:26
  • yeah, I did that to every delegate object that I could think of that contains a scrollview, but the crash is still there. Is there a way to identify which object it is? I can't reproduce this in sim, so have to rely on device crashes. – Jimmy Xu Aug 19 '15 at 17:28
  • @JimmyXu Did you get the solution? – meteors Nov 02 '15 at 17:05
  • 1
    @meteors yes, it looks like we had missed some UIScrollView subclasses that also needed their delegates to be set to nil on dealloc. The specific one being UITextView. – Jimmy Xu Nov 02 '15 at 18:49

1 Answers1

0

this may be the same as the following issue. basically set UIScrollView's delegate to nil in dealloc

Unable to find reason for Crash on -[UIScrollView(UIScrollViewInternal) _scrollViewAnimationEnded:finished:]

Community
  • 1
  • 1
calql8edkos
  • 429
  • 4
  • 13