(lots of) UIWebView memory leaks

白昼怎懂夜的黑 提交于 2019-12-19 12:08:08

问题


I've seen from other posts that there are memory leaking issues with UIWebView. However, with the amount of objects that I have leaking, I have to wonder if I'm doing something wrong. 'Leaks' reports about 60 leaks for opening a UIWebView, loading a page and closing (it's the Facebook login page). I've check the stack trace for every one of these objects, and they never touch my code. They're all either in a separate thread (I only use the main thread), or go from 'main' to a bunch of internal methods that are greyed out. Is this expected from UIWebView? I'm running the latest firmware, and I think they would have fixed this by now. I'm seeing this on the device, by the way. I also tried checking for bugs on the apple site, but there's no way to search other than by issue ID..?

Shaun

Here's a capture of the leaks:


回答1:


Sorry to answer my own question so quickly, but I just found the problem.

If you return NO for the delegate method:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;

and then release the UIWebView, it will leak as described above. Returning YES fixes the issue. At least for me, this is happening on all firmware revisions up to now (4.3.3). I am filing a bug with Apple.




回答2:


Fellows! I cnow it's a bit late %) Researched this theme for a while and found a solution that works for me the best - use WKWebView it doesn't leak! That's it - so simple.



来源:https://stackoverflow.com/questions/6421813/lots-of-uiwebview-memory-leaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!