iOS UIWebView漏掉了 [英] iOS UIWebView leaked

查看:190
本文介绍了iOS UIWebView漏掉了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class MyViewController: UIViewController {
     @IBOutlet weak var webView: UIWebView?
     override func viewDidLoad() {
    super.viewDidLoad()

    let url = NSURL(string: urlString)
    let request = NSURLRequest(URL: url!)
    SVProgressHUD.show()

    webView?.loadRequest(request)
    webView?.scrollView.header = MJRefreshNormalHeader(refreshingBlock: {

      [weak self] in
      if let strongSelf = self {
        strongSelf.webView?.reload()
      }})   }
     override func viewDidDisappear(animated: Bool) {
    super.viewDidDisappear(animated) 

    SVProgressHUD.dismiss()   }    }

extension MyViewController: UIWebViewDelegate {
     func webViewDidFinishLoad(webView: UIWebView) {
    webView.scrollView.header.endRefreshing()
    SVProgressHUD.dismiss()   }       func webView(webView: UIWebView, didFailLoadWithError error: NSError?) {
    webView.scrollView.header.endRefreshing()
    SVProgressHUD.dismiss()   }    }

视图控制器是由导航控制器推动的,当我弹出它时,我得到了泄漏。在instrument.Leak我看到了这些。

The view controller was pushed by a navigation controller, when I pop it, I got leaks. In instrument.Leak I saw these.

Leaked Object   #   Address Size    Responsible Library Responsible Frame NSMutableArray    1   0x137a6ddb0 48 Bytes    UIKit   -[_UIKeyboardTextSelectionGestureController init]
_UIKeyboardTextSelectionController  1   0x137a6e800 96 Bytes    UIKit   -[UIWebSelectionAssistant addNonEditableForceTextSelectionGestureRecognizersToView:]
_UIKeyboardBasedNonEditableTextSelectionGestureController   1   0x137a6dcd0 160 Bytes   UIKit   -[UIWebSelectionAssistant addNonEditableForceTextSelectionGestureRecognizersToView:]





我确定webView,myViewController被延迟,但是当弹出myViewController时,4M增加而不是释放。请帮助和谢谢。

#

I'm sure that the webView, myViewController were delayed, but when pop the myViewController, 4M increased and not release. Please help and thanks.

列表项目

推荐答案

根据< a href =https://forums.developer.apple.com/thread/24539\"rel =nofollow noreferrer>这里发布的答案,有一种解决方法,如果你设置 configuration.selectionGranularity WKSelectionGranularityCharacter ,泄漏停止:

According to an answer posted here, there is a workaround that if you set configuration.selectionGranularity to WKSelectionGranularityCharacter, the leaks stop:

let config = WKWebViewConfiguration()
config.selectionGranularity = .character //WKSelectionGranularityCharacter
let myWebview = WKWebview(frame: frame, configuration: config)

这对我有用,但是当选择文本时,webview中没有选择矩形。在您的情况下,这可能是也可能不是可行的解决方法。

This worked for me, but then, when selecting text, there was no selection rectangle in the webview. This may or may not be a viable workaround in your case.

编辑我刚注意到您的问题是针对UIWebView,而不是WKWebView。看起来你不能在UIWebView上设置它。我现在要留下这个答案,因为WKWebView的人搜索这个内存泄漏可能会找到这个帖子......

Edit I just noticed your question is for UIWebView, not WKWebView. It doesn't look like you can set this on UIWebView. I'll leave this answer for now since WKWebView folks googling this memory leak will probably find this thread...

这篇关于iOS UIWebView漏掉了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆