My project is a hybrid static lib for showing a UIWebView with some JS to control the logic. When I use 64bit and run demo on iOS 8/iPhone 6, the memory keeps going to 30M or more!
When I use generation in instrument, the increased memory usage is almost all from webcore; does it means there are leaks in JS code? I can't find a leak when I use Safari to run similar JS directly.
When I release the UIWebView, the memory is still not freed; I tested with instrument allocation. There are some webcore and (non - object) still in memory, what can I do to release them?
I use the following code.
-(void)createUIWebview{
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:serviceUrl]]];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
}
-(void)dealloc{
if (_webView.isLoading){
[_webView stopLoading];
}
[_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
_webView.delegate=nil;
[_webView removeFromSuperview];
[_webView release];
_webView = nil;
}
I have researched the following links, but they don't seem to solve my problem. Is UIWebview still leaking in iOS 8? And the problem seems not so obvious when I use iOS 6 in iPhone4.
Whats the proper way to release a UIWebView?
iOS 8 UIWebView memory management
UIWebView leaks, JS Garbage Collector & WebCore VMs
Release memory/cookie/cache from UIWebView once closed
I was having the same problem and switched to the new WKWebView
and it immediately solved all of the memory leak issues I was seeing. WKWebView
shares many of the same call names from UIWebView
so all I had to do on my project is switch over all my `UIWebView' objects to 'WKWebView' and the memory leaks went away.
Remember to import the WebKit
into your project and know that is is only available on iOS8
.
Apple Documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With