WKWebView释放

点进一个web页面没问题,但是返回的时候crash。错误信息如下

2017-08-18 19:29:52.734 BluedInternational[11600:1646954] dealloc
objc[11600]: Cannot form weak reference to instance (0x5225200) of class GJWebViewController. It is possible that this object was over-released, or is in the process of deallocation.
(lldb) bt

  • thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BREAKPOINT (code=EXC_ARM_BREAKPOINT, subcode=0xdefe)
    • frame #0: 0x20bf2a44 libobjc.A.dylib_objc_trap() frame #1: 0x20bf2aa8 libobjc.A.dylib_objc_fatal(char const, ...) + 72
      frame #2: 0x20c0c412 libobjc.A.dylibweak_register_no_lock + 210 frame #3: 0x20c0c7b8 libobjc.A.dylibobjc_storeWeak + 208
      frame #4: 0x25a8489a UIKit-[UIScrollView setDelegate:] + 306 frame #5: 0x283c6f30 WebKit-[WKScrollView _updateDelegate] + 228
      frame #6: 0x283d09fe WebKit-[WKWebView dealloc] + 266 frame #7: 0x20c0d3a8 libobjc.A.dylib(anonymous namespace)::AutoreleasePoolPage::pop(void
      ) + 388
      frame #8: 0x21366f88 CoreFoundation_CFAutoreleasePoolPop + 16 frame #9: 0x2141806e CoreFoundation__CFRunLoopRun + 1582
      frame #10: 0x21367228 CoreFoundationCFRunLoopRunSpecific + 520 frame #11: 0x21367014 CoreFoundationCFRunLoopRunInMode + 108
      frame #12: 0x22957ac8 GraphicsServicesGSEventRunModal + 160 frame #13: 0x25a3b188 UIKitUIApplicationMain + 144
      frame #14: 0x0007cf62 BluedInternationalmain(argc=1, argv=0x0361bab8) at main.m:13 frame #15: 0x2100f872 libdyld.dylibstart + 2
      (lldb)
      分析发现,在WKWebView释放之后竟然还进行了scrollView代理的设置,而这个时候的self,也就是当前的控制器处于销毁当中,也就解释了上面log提到的or is in the process of deallocation.。所以加入你的WKWebView是懒加载的,不要在懒加载中设置代理,其次在dealloc中将代理置为nil。
      遇到记录下
      转载:https://www.jianshu.com/p/b3d97cdeb4c5

你可能感兴趣的:(WKWebView释放)