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?
- 0JavaScriptCore WTF::MallocHook::recordAllocation(void*, unsigned long)
- 1 JavaScriptCore WTF::fastMalloc(unsigned long)
- 2 WebCore WebCore::SharedBuffer::buffer() const
- 3 WebCore WebCore::SharedBuffer::data() const
- 4 WebCore WebCore::ResourceLoader::didReceiveDataOrBuffer(char const*, unsigned int, WTF::PassRefPtr, long long, WebCore::DataPayloadType)
- 5 WebCore WebCore::SubresourceLoader::didReceiveDataOrBuffer(char const*, int, WTF::PassRefPtr, long long, WebCore::DataPayloadType)
- 6 WebCore WebCore::SubresourceLoader::didReceiveBuffer(WTF::PassRefPtr, long long, WebCore::DataPayloadType)
- 7 WebCore WebCore::ResourceLoader::didReceiveBuffer(WebCore::ResourceHandle*, WTF::PassRefPtr, int)
- 8 WebCore WebCore::SynchronousResourceHandleCFURLConnectionDelegate::didReceiveDataArray(__CFArray const*)
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
WKWebView
does not inherit fromUIWebView
, it's a completely new and different class. If you're on iOS 8 only you should definitely use it overUIWebView
. You should also be using ARC. – Fatsoluble