gpt4 book ai didi

iOS UIWebView 泄露

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:42 48 4
gpt4 key购买 nike

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() } }

View Controller 由导航 Controller 推送,当我弹出它时,我得到了泄漏。在 instrument.Leak 我看到了这些。

#

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 增加了并且没有释放。请帮忙,谢谢。

列表项

最佳答案

根据 an answer posted here ,有一个解决方法,如果您将 configuration.selectionGranularity 设置为 WKSelectionGranularityCharacter,泄漏就会停止:

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

This worked for me, but then, when selecting text, there was no selection rectangle in the webview.对于您的情况,这可能是也可能不是可行的解决方法。

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

关于iOS UIWebView 泄露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32688401/

48 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com