Memory leaks using UIWebView and NSURL: for several days we tried to solve them

I already found a lot of information on how to solve the memory leak problem for the iPhone Obj C code. The last two leaks puzzled me, I probably miss something. Maybe you can notice it.

The tools report 2 leaks for the following code (part of a subclass of UIViewController):

(1) UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height - LOWER_VERT_WINDOW_MARGIN)]; (2) webView.scalesPageToFit = YES; (3) webView.dataDetectorTypes = UIDataDetectorTypeNone; (4) (5) NSURL *url = [NSURL fileURLWithPath:self.fullPathFileName isDirectory:NO]; (6) NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url]; (7) [webView loadRequest:urlRequest]; (8) [urlRequest release], urlRequest = nil; (9) [self.view addSubview:webView]; (10) [webView release], webView = nil; 

The device orders 128 bytes flow on line 1, as well as 256 bytes on line 4. I don’t know if this means line 3 or line 5.

Does anyone know what I'm missing?

+1
source share
1 answer

1) Make sure you test the leak on the device, not on the simulator

2) Otherwise, try setting up the url cache by adding this to your applicationDidFinishLaunching in your application delta:

 NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release]; 
+5
source

All Articles