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

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

问题描述

我们的应用程序的主屏幕(因此是所有用户首次看到的)有几个部分,其中大部分包含用户可能想要打开的不同webview。这样做可以将内存使用量从仅仅26MB增加到85MB甚至更多(打开所有不同的webview后)。

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必须打开的资源因为,稍后,我们的应用程序中有一个非常苛刻的部分需要大量内存并且如果您以前浏览过其中几个Web浏览器,则会完全崩溃应用程序。

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;)

编辑:我刚从头创建了一个项目,添加了一个webview和一个按钮,每次点击它都会加载一个不同的网页,反过来增加了内存使用量。我还添加了一个按钮,在点击时会破坏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天全站免登陆