Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to properly remove an instance of UIWebView and avoid memory leaks
// Destroy UIWebView
- (void)destroyWebView
{
[self.webView loadHTMLString:@"" baseURL:nil];
[self.webView stopLoading];
[self.webView setDelegate:nil];
[self.webView removeFromSuperview];
[self setWebView:nil];
[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
}
// UIWebViewDelegate Methods
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
@capripot

This comment has been minimized.

Show comment Hide comment
@capripot

capripot Jan 20, 2014

Is it still the case ?
Why do you use webView:shouldStartLoadWithRequest:navigationType: ?

Is it still the case ?
Why do you use webView:shouldStartLoadWithRequest:navigationType: ?

@Mr-Mojo-Risin

This comment has been minimized.

Show comment Hide comment
@Mr-Mojo-Risin

Mr-Mojo-Risin May 14, 2014

It does not work very well.

It does not work very well.

@sealedace

This comment has been minimized.

Show comment Hide comment
@sealedace

sealedace May 18, 2015

Not work for me.

Not work for me.

@ArtSabintsev

This comment has been minimized.

Show comment Hide comment
@ArtSabintsev

ArtSabintsev Aug 4, 2015

I have no idea if this works anymore. I put this solution together in early 2013, from a project I worked on in 2012.

Owner

ArtSabintsev commented Aug 4, 2015

I have no idea if this works anymore. I put this solution together in early 2013, from a project I worked on in 2012.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment