Memory leak in Font Glyph / UIWebView
Asked Answered
B

1

8

I just found that when UIwebview get dealloc-ed, most of the memory it used doesn't get totally recycled. After doing some profile, i found most of the still alive memory are Font glyph cache(the problem is much worse if you are open a chinese web page, as chinese has more characters, which means more font glyph).

Is there any way we can control the cache ? I'm working on a iOS web browser, this problem blocks me for 2 weeks.

Attached is a simple repro demo. 1) Run the demo with memory "Allocation profile". 2) input http://www.163.com in the address bar and waiting it's finished loading. 3) you can see around 10M memory consumed in the instrument tool. 4) click the clear button(the UIwebview will be removed from the visual tree and get recycled) 5) you can still see around 9M memory alive.

BTW, NSURLCache was disabled with below code, to separate the problem. [[NSURLCache sharedURLCache] setMemoryCapacity:1]

Burgas answered 23/2, 2012 at 2:45 Comment(4)
I'm trying to investigate how Mobile safari deal with this problem. is there any way i can print import symbol table with otool? otool -ov print all the symbols defined in this application, but i want to know which symbol this app linked from other dynamic library. I use class-dump-z to dump all the header files, but doesn't get any useful information.Burgas
The actual problem is in draw_glyphs in CoreGraphics, After CGFontCreateGlyphBitmap , the bit map get cached, and no way we can control the cache. it's not a leaking but on iPad1 it's really a problem for my application(With a lot of text)Burgas
Did you ever find the answer to this? I'm also trying to avoid issues with UIWebView font memory.Brinker
@Burgas the link for the attached demo is broken. I think I'm suffering from the exact same problem at Unable to Completely Reclaim Memory Usage from UIWebView.Noninterference
M
0

We observed similar problems in our production application. I created a reduction of the bug where I repeatedly clear the web view (load "<html></html>") then load the following URL in a UIWebView:

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

This reliably crashes the application after about 180 loads. I have filed a bug report for this with Apple as Problem ID 15659596, and I'm waiting for a response.

However, I'm still unclear in what situations this occurs exactly and when it doesn't. Obviously, it happens for that URL, but I've also tested the same procedure with:

  1. The same web content that observed the issue in the wild in our application
  2. A Google Image Search for terms like "cat" and "dog".

In both these scenarios, the problem doesn't appear. I observe no long-term memory usage growth and the application doesn't crash.

So I don't have any answer for you, but I can confirm that an issue does exist with the UIWebView, that I've reported it to Apple, and that it does appear to be related to web fonts.

Militate answered 16/12, 2013 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.