Memory leak leading to crash in UIWebView when loading pages using web fonts.

Originator:michael.melanson
Number:rdar://15659596 Date Originated:13-Dec-2013
Status:Open Resolved:
Product:iOS Product Version:
Classification: Reproducible:
 
Summary:
When a UIWebView is made to repeatedly load pages, especially those which make use of Web Fonts, it retains memory afterwards after another page is loaded.

Eventually, the device's memory is exhausted and the application crashes.

I have attached a sample application which exhibits the behaviour. This sample code is a reduction of a production application where we observed the crash after 30-100 page loads. It cycles between an image-heavy page (Google Image Search for "cats") and a font-heavy page (Google web fonts preview page) at a rate of about one cycle every 10 seconds.

Steps to Reproduce:
With Instruments attached in Allocations mode:

1. Run the attached sample application. 
2. Wait.

Expected Results:
The application continues indefinitely without crashing. No long-term memory usage growth is observed.

Actual Results:
In one test run, each page load increases the memory usage by ~5-300KB on average. After about 1 hour 30 minutes, it began receiving memory warnings with increasing frequency. After 2 hours 1 minute 30 seconds, the application receives many memory warnings and crashes.

Version:
iOS 7.0.4 (11B554a)

Notes:


Configuration:
The sample code also includes an alternate URL (TSViewController.m:43) for Google Image Search for "dogs". When using this alternate URL, the application exhibits much lower memory growth (though not zero) and does *not* crash after ~3h of run time. 

Tested on a 32GB iPad 2,2. In testing our production application, we have also observed the crash on an iPad 3.

Comments

Sample application can be found here: https://www.dropbox.com/s/dgtwo9416rsd64d/UIWebViewLeak-1.zip?dl=0

By michael.melanson at Nov. 19, 2014, 2:47 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!