开发者

Memory leaks with UIWebView and NSURL: already spent several days trying to solve them

I have already found a lot of information about how to solve memory leaks for iPhone Obj C code. The last two leaks keep me puzzled, I'm probably overlooking something. Maybe you can spot it.

Instruments reports 2 leaks for the following code (part of a UIViewController subclass):

(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 loadReque开发者_开发百科st:urlRequest];
(8)  [urlRequest release], urlRequest = nil;
(9)  [self.view addSubview:webView];
(10) [webView release], webView = nil;

Instruments claims 128 bytes are leaking in line 1, as well as 256 bytes in line 4. No idea if it means line 3 or line 5.

Does anybody have a clue what I'm overlooking?


1) Make sure you are leak testing on a device and not the simulator

2) Failing that, try setting the url cache by adding this to your applicationDidFinishLaunching in your app delegate:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜