ios UIWebView 中的大量内存泄漏 [英] massive memory leak in ios UIWebView

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

问题描述

在我们系统的其他地方寻找内存泄漏,我创建了一个带有元刷新标签的 20 MB 网页.我们的想法是通过我们的数据路径代码移动大量数据以确认内存稳定性.

looking for mem leaks elsewhere in our system, I created a 20 MB web page with a meta refresh tag. the idea was to move a lot data through our datapath code to confirm mem stability.

<html>
<meta http-equiv="refresh" content="1">
<body>
<div style="border: 1px solid red">
    Content loading
</div><!-- 20mb worth of comments -->
</body>
</html>

我发现 uiwebview 显示元刷新页面非常非常快地泄漏内存.应用内存在大约 2 分钟内达到 300mb,并在内存不足警告时被击中,即使我们的代码不在运行中.

what I found was the uiwebview displaying that meta refresh page leaks memory very, very fast. the app memory hits 300mb in about 2 minutes and gets shot on a low mem warning, even when our code is not in play.

我已停止刷新加载并尝试取消分配 webview.

I have stopped the refresh loading and tried to dealloc the webview.

我试过 loadurl:"about:blank", loadhtml:"", javascript document close.

I have tried loadurl:"about:blank", loadhtml:"", javascript document close.

我也尝试写一个递归的removeFromSuperview和removeFromParentViewController,读到webview中的私有scrollview是一个内存问题,但那个内存永远不会被释放.我似乎无法找到一种可靠的方法来关闭、在我们完成后释放 web 视图.

I also tried writing a recursive removeFromSuperview and removeFromParentViewController, reading that the private scrollview in the webview is a memory problem, but that memory is never freed. I can't seem to find a reliable way to close, dealloc a webview when we are done with it.

我们已经忍受了 webview 泄漏的缓慢速度,真的很想找到一种方法来确保 webview 在我们完成后可以被完全清理.我们最近将应用程序转换为 ARC,这并没有改变内存速率.

We have lived with a slow rate of webview leaking for quite a while and really want to find a way of assuring a webview can be fully cleaned up when we are done with it. We recently converted the app to ARC which did not change the memory rate.

我正在考虑通过 webview 中的所有对象尝试递归循环,看看它们是否可以被释放.仪器显示 20 MB 的 cfdatas,活着,每次刷新 20MB 页面,但不会将它们显示为泄漏.如果我只传递响应头并完成到 urlprotocol 客户端,我们就可以稳定运行,因此可以确认其余数据路径中的 memleaks,但这是一个如此戏剧性的测试用例结果,我希望能找到一次 webview mem 泄漏解决方案和所有人.

I am considering trying a recursive loop through all the objects in the webview and see if they can be freed. instruments shows 20 mb of cfdatas, alive, for each refresh of the 20MB page, but does not show them as leaks. if i only deliver the response header and done to the urlprotocol client we run stably so was ale to confirm the memleaks in the rest of the data path, but this is such a dramatic test case result am hoping to find a webview mem leak solution once and for all.

有没有人有更好的想法,或者有没有人尝试过递归遍历 uiwebview 中的对象?

Does any one have any better ideas or has anyone tried recursing through the objects in a uiwebview?

推荐答案

我摆脱 UIWebView 内存泄漏的方法是将其 HTML 设置为空字符串.一个地方是当包含 web 视图的视图控制器消失时:

The way I got rid of my UIWebView's memory leakage is by setting its HTML to the empty string. One place to do this is when the view controller containing the web view disappears:

- (void) viewWillDisappear:(BOOL)animated {
    if (self.isMovingFromParentViewController) {
        [self.wv loadHTMLString: @"" baseURL: nil];
    }
}

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

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