IOS 8 memory management UIWebView

I have a hierarchical application (NavigationController) with a simple view of the table as the root controller. Each time you select any cell, you have a new view with some information about the details (controlled by DetailViewController). On the view side of the DetailViewController, I have a UIWebView to display data from the Internet. But the problem arises when I look at memory usage. Each new open ViewViewController, with its contents downloaded from the Internet via UiWebView, brings more memory using the coefficient. I would like to unload everything and free the memory allocated for this data when I get back to the root controller view.

How do I solve this problem? I tried using the stopLoading: UIWebView instance method to save some memory, but this also does not solve the problem. As I do not quite understand the ARC process, I cannot provide for myself if I usually have increased memory using a coefficient with each new open detailed view.

Thank you in advance!

+6
source share
1 answer

A few comments. UIWebView "leaks". It runs with at least iOS4. With every large page load, it seems to grow, and memory is not fully restored when the UIWebView object itself is freed. Regardless of whether this memory remains in the cache and when it is really needed, or a leak, I could not answer correctly. This has improved somewhat over the years, but can still be seen using the instrument memory allocation graph.

Let's start with the basics. Before embarking on a design change, try using the tools to see what exactly is happening. You can also subclass your views and view controllers, implement their dealloc methods, and ensure that they are correctly released when expected. Many times, especially when blocks are involved, people create save cycles that cause huge memory leaks. Do it first.

Here are some suggestions for my experience with WebKit:

  • Use the web view as much as possible. If you can, use the same object and just add it as a subview of the views of the view controllers.
  • We noticed that most of all we could drain from the web view, opening a blank page before releasing the UIWebView object.
  • iOS8 supports the new model when working with WebKit: WKWebView (WebKit2). In this model, web content is managed and distracted from the process, and memory is β€œleaked” in the process. If necessary, the OS will kill this WebKit process, which will allow your application to work. You can try this and see if you have any improvements.
+9
source

Source: https://habr.com/ru/post/975924/


All Articles