[iOS9] WebView memory leak on selecting input text field

We develep an app using UIWebView, and the app gets memory leak on every time use selects a text input field within the webview.

This happens only on iOS9 devices, and As text field is selected, our app gets significantly slower.

To try fixing this issue, we've built simple web view apps doing nothing but display https://google.com with both of UIWebView and WKWebView.

The result was that both reproduced the memory leak when selecting input field on both of simulator and actual devices.


Leak Instruments showed responsible frames causing memory leak below.

  • [UIWebSelectionAssistant addNonEditableForceTextSelectionGestureRecognizersToView:]
  • [UIKeyboardTextSelectionGestureController init:]


Does anyone have the same issue?

We'd like to know whether this is iOS bug or not, and any solution.

Thanks in advance.


Dev Environment : Xcode 7.1

Tested devices : iOS 9.0.2, 9.1

Replies

I am having exactly the same issue. Not duplciable on iOS 8.x, but easily reproducible on iOS 9.1.

We have the exact same problem here.


It looks like I'll have to build a Phonegap plugin in order to destroy the webview 😠

Same problem for me.

same to me. I recently embed a UIWebView and start seeing memory leak. iOS 8 simulator does not have such leak though.


footprint:

Leaked Object

#

Address

Size

Responsible Library

Responsible Frame

_UIKeyboardTextSelectionController

2

< multiple >

192 Bytes

UIKit

-[UIWebSelectionAssistant addNonEditableForceTextSelectionGestureRecognizersToView:]

_UIKeyboardBasedNonEditableTextSelectionGestureController

2

< multiple >

320 Bytes

UIKit

-[UIWebSelectionAssistant addNonEditableForceTextSelectionGestureRecognizersToView:]

NSMutableArray

2

< multiple >

96 Bytes

UIKit

-[_UIKeyboardTextSelectionGestureController init]

The best thing to do is to file a bug report. If it's possible to isolate this issue down to a simple sample project that would be extremely helpful for us to help diagnose and fix this if it's a leak in WebKit or UIKit.

Hi pdm,

I submitted what you are asking for on ticket 23664543...it includes a reduced test case (and a narrated instructional video) that makes Webkit (UIWebView and WKWebView) crawl within 1-2 minutes. If there is any more information that I can provide to help, please don't hesitate to ask.


Best Regards,

Kevin

pdm,

I forgot to mention that I submitted this report back in November. Any feedback on the progress would be greatly appreciated.


-Kevin

I was able to reproduce the same performance degradation on the Mobile Safari browser (without Webview). I created a simple html file with nothing but text inputs....as I traversed through the inputs, the browser tab took a severe hit in performance. Navigating to another address and returning to my test page restored the expected performance to the browser tab.

Hey,


Same issue on my side, both for UIWebview & WKWebView.

When recreating webview there are lots of low memory warnings.

Any feedback on the progress would be greatly appreciated,

Best,

Eliza

I ran into this issue tonight and didn't see much info outside this post. I think I found a workaround that worked for me.


After setting the configuration.selectionGranularity to WKSelectionGranularityCharacter my Instruments profiling is nice and clean.

Thank you!! I've been searching for answers for months and your suggestion worked!

can you tell me the solution? how to resolved it?

http://7xq04x.com1.z0.glb.clouddn.com/wkwebviewmemoryleaks.png


Same for me.

The link above shows the memory leaks detacted by Instruments

I belive that I spoke too soon. The solution posted by 'thejason' helped prevent the noticable performance hit caused by the memory leak....however, in lieu of the app progressively slowing down, it just locks up when it uses all of it's memory. Unfortunately, It was after I upgraded half of the iPad's in the company when I had realized this. I am now in the process of adding some code to programatically force close the app twice a day in a desparate attempt to disguise this as a periodic "cleanup" rather than a "crash". Since we are running in 'Single App Mode', the app restarts instantly after it is killed.

_webView is WKWebView

_webView.configuration.selectionGranularity = WKSelectionGranularityCharacter;

changed the thing like you said but having same leak issues.