使用后释放 iOS UIWebView 资源 [英] Freeing iOS UIWebView resources after usage

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

问题描述

我们应用的主屏幕(因此是所有用户最先看到的)有几个部分,其中大部分包含用户可能想要打开的不同 Web 视图.这样做会将内存使用量从勉强 26MB 增加到高达 85MB 甚至更多(在打开所有不同的 web 视图之后).

Our app's home screen (and therefore the first seen by all users) has several sections, most of which contain diferent webviews the user may want to open. Doing so increases memory usage from barely 26MB to up to 85MB or even more (after opening all diferent webviews).

我们发现的问题是,一旦它们关闭,所有网页资源似乎都保留在内存中(使用的内存可能几乎不会减少几 MB).

The problem we found is that, once they're closed, all web page resources seem to be kept at memory (used memory barely decreases a couple of MB perhaps).

我想释放 webview 必须打开的资源,因为稍后,我们的应用程序中有一个非常苛刻的部分需要大量内存,如果您碰巧浏览了几个之前的那些网页浏览量.

I would like to free the resources the webview had to open because, later on, there's a very demanding section of our app which needs a lot of memory and completely crashes the app if you happen to have been browsing through several of those webviews before.

我在互联网上找到了几个可以尝试的选项,但到目前为止都没有奏效.诸如:

I have found several options on the internet to try but none of them have worked so far. Things such as:

// Try to clean used webview

[self.webView loadHTMLString:@"" baseURL:nil];
[self.webView stopLoading];
self.webView.delegate = nil;
[self.webView removeFromSuperview];
self.webView = nil;

它们对内存使用几乎没有影响.我在这里有什么遗漏吗?我已经仔细检查过我没有任何泄漏会使 WebView 保持打开状态,我已经释放了对它的唯一引用 (self.webView = nil;)

They've made absolutely almost no effect on memory usage. Is there anything I'm missing here? I already double checked that I have no leaks that would keep the WebView opened, I'm already freeing the only reference to it that I have (self.webView = nil;)

我刚刚从头开始创建了一个项目,添加了一个 web 视图和一个按钮,每次单击它都会加载不同的 web,这反过来又增加了内存使用量.我还添加了一个按钮,当点击该按钮时会破坏 webview,你猜怎么着,内存保持不变,就像它实际上没有释放任何资源一样.

I just created a project from scratch, added a webview and a button which loads a different web every time I click it, which in turn increases memory usage. I also added a button that will destroy the webview when clicked and, guess what, memory stays the same, like it's effectively not releasing any resources.

推荐答案

我问这个问题已经好几个月了,似乎没有人知道任何解决方法,所以我只是回答自己给它一些结束,可悲的是,对于遇到同样问题的人来说,这是个坏消息.

It's been several months since I asked this question and it seems no one knows any work around, so I'm just answering myself to give it some closure and, sadly, bad news to whoever is having this same issue.

几天来,我们一直在努力解决这个问题,在与一些人交谈后,他们以某种方式暗示我们对此无能为力(这只是一个不同的过程,负责处理我们无法访问的所有事情),我们决定限制 webview 访问自定义页面.

We kept trying to fight this issue for several days and, after talking to some people who somehow hinted us that we had nothing to do about it (it's just a different process taking care of everything to which we have no access), we decided to restrict the webview access to custom made pages.

例如,我们有一个新闻栏目,可以在互联网上打开网页.我们最终做的是打开包含标题、正文和与新闻相关的图像的定制网页(这仍然会增加资源内存使用,但我们设法将它保持在一个包含的小格式中,这需要数千新闻公开有任何危险).我知道,不理想.

For example, we had a news sections which opened webs on the internet. What we ended up doing was open custom-made web pages which contained the title, body and an image related to the news (which still adds to resource memory usage, but we managed to keep it in a contained small format which would need thousands of news to be opened to be of any danger). I know, not ideal.

我仍然希望看到对这个问题的一些建设性答案,无论是解决方案、变通方法,还是任何可以帮助未来遇到同样问题的用户提供有关如何处理它的线索的想法.

I'd still love to see some constructive answers to this question, whether it's a solution, a workaround, or any idea that can help future users with this same issue have clues on how to deal with it.

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

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