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

查看:348
本文介绍了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文档关闭。

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

我还尝试编写一个递归的removeFromSuperview和removeFromParentViewController,读取webview中的私有scrollview是一个内存问题,但该内存永远不会被释放。当我们完成它时,我似乎无法找到一种可靠的方法来关闭,取消一个webview。

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的方法,当我们完成它时可以完全清理。我们最近将应用程序转换为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中的所有对象进行递归循环,看看它们是否可以释放。仪器在20MB页面的每次刷新时显示20mb的cfdatas,alive,但不会将它们显示为泄漏。如果我只提供响应头并完成urlprotocol客户端我们运行稳定,所以是ale确认其余数据路径中的memleaks,但这是一个如此戏剧性的测试用例结果我希望找到一个webview内存泄漏解决方案一次并为所有人。

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天全站免登陆