Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freeing iOS UIWebView resources after usage

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

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

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; 

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

Edit: 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.

like image 327
h4lc0n Avatar asked Jan 16 '14 12:01

h4lc0n


People also ask

Is UIWebView deprecated?

Apple is phasing out UIWebView, which is used by developers for integrating web content into an app in a quick and secure manner. Apple is replacing UIWebView (and WebView) with WKWebView, an updated version, as UIWebView has been deprecated.

How do I release WKWebView?

Common Ways That Developers Leak WKWebViews The most common way to leak WKWebViews is to allocate new ones instead of reusing ones that you've already created. Sometimes, engineers think they are properly reusing webviews, but they do not check for buildups of WKWebView instances when profiling in Xcode.

What is UIWebView on Apple iPhone?

A view that embeds web content in your app.

When was UIWebView deprecated?

New apps containing these frameworks are no longer accepted by the App Store. And last year, we announced that the App Store will no longer accept app updates containing UIWebView as of December 2020.

Is it too late to publish an iOS app with UIWebView?

This warning was still a warning and would not prevent you from publishing your app at the time. A few months after this, Apple announced that as of April 2020 they reject new apps still referencing UIWebView. For updates to apps the deadline is December 2020. Of course, we want to be ready well before then, and we are.

What happened to UIWebView in iOS 13?

Shortly after the introduction of iOS 13, Apple decided to send out warning messages about the UIWebView deprecation. The warning would read: ITMS-90809: Deprecated API Usage – Apple will stop accepting submissions of apps that use UIWebView APIs.

What happened to the uiwebviewrenderer in forms?

While it has been available in Forms for a long time now, the default was still the UIWebViewRenderer. Shortly after the introduction of iOS 13, Apple decided to send out warning messages about the UIWebView deprecation. The warning would read: ITMS-90809: Deprecated API Usage – Apple will stop accepting submissions of apps that use UIWebView APIs.

What is the deadline for UIWebView updates?

A few months after this, Apple announced that as of April 2020 they reject new apps still referencing UIWebView. For updates to apps the deadline is December 2020. Of course, we want to be ready well before then, and we are.


1 Answers

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.

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.

like image 108
h4lc0n Avatar answered Sep 25 '22 04:09

h4lc0n