title: iOS 12+ Memory Leak - WKWebView and UIWebView
body: <p>This is not a question, but I'm posting here in the hope that it will save someone else's sanity (I've just spent the best part of a day figuring this one out). I've identified a memory leak that has appeared from iOS 12.0+, which affects WKWebView and UIWebView. The leak appears as soon as you instantiate either of the 2 webviews. Instruments identifies the leak as coming from JavaScriptCore, which I guess is why it affects both webviews equally.</p>
  
  <p>I was trying to figure out what I was doing wrong, when I decided to try an older iOS version (11.4 - the version before 12.0), and I noticed the leak had disappeared. I can reproduce this every time.</p>
  
  <p>To reproduce, all you need to do is allocate an instance of a webview on a class.</p>
  
  <pre><code>let webview = WKWebView()
  </code></pre>
  
  <p>or</p>
  
  <pre><code>let webview = UIWebView()
  </code></pre>
  
  <p>Immediately, you'll notice 4 leaks on iOS 12.0/12.1, which are no longer present if you run the code on iOS 11.4. There are 4 separate leaks; 3 x 96 bytes and 1 x 128 bytes.</p>
  
  <p><a href="https://i.stack.imgur.com/hQtDp.png" rel="noreferrer"><img src="https://i.stack.imgur.com/hQtDp.png" alt="Leak-WKWebView"></a></p>
  
  <p>I've filed a bug with Apple via the BugReporter, duplicated at Openradar: <a href="https://openradar.appspot.com/radar?id=6132657108811776" rel="noreferrer">https://openradar.appspot.com/radar?id=6132657108811776</a></p>