Glyph / UIWebView Font Memory Leak

I just found that when UIwebview gets dealloc-ed, most of the memory used is not completely recyclable. After completing some profile, I found that most of the remaining memory is the font cache (the problem is much worse if you open a Chinese web page, since the Chinese have more characters, which means more font characters).

Is there any way to manage the cache? I am working on an iOS web browser, this problem has been blocking me for 2 weeks.

Attached file is a simple demo to play. 1) Run the demo with the memory "Distribution Profile". 2) enter http://www.163.com in the address bar and wait for the download to complete. 3) you can see about 10 M of memory consumed in the instrument. 4) click the clear button (UIwebview will be removed from the visual tree and recycled) 5) you can still see about 9M of memory.

BTW, NSURLCache has been disabled using the code below to separate the problem. [[NSURLCache sharedURLCache] setMemoryCapacity: 1]

+7
source share
1 answer

We observed similar problems in our manufacturing application. I created an error reduction when I repeatedly clear the web view (load "<html> </html>"), then load the following URL into the UIWebView:

http://typecast.com/preview/google/Mr%20Bedfort/Sigmar%20One/Miss%20Fajardose 

This provides a reliable application crash after approximately 180 loads. I wrote a bug report with Apple as problem identifier 15659596, and I'm waiting for an answer.

However, I still do not understand in what situations this happens exactly, and when not. Obviously this happens for this url, but I also checked the same procedure with:

  • The same web content that noticed a problem in the wild in our application
  • Search Google Image for terms such as "cat" and "dog."

In both of these scenarios, the problem does not occur. I do not observe a long-term increase in memory usage, and the application does not crash.

So, I have no answer for you, but I can confirm that the problem exists with the UIWebView, which I reported to Apple about it, and that it seems to be related to web fonts.

0
source

All Articles