UIWebView leak? Can someone confirm?
Posted
by Shaggy Frog
on Stack Overflow
See other posts from Stack Overflow
or by Shaggy Frog
Published on 2010-04-01T03:23:44Z
Indexed on
2010/04/01
3:33 UTC
Read the original article
Hit count: 606
I was leak-testing my current project and I'm stumped. I've been browsing like crazy and tried everything except chicken sacrifice. I just created a tiny toy project app from scratch and I can duplicate the leak in there. So either UIWebView
has a leak or I'm doing something really silly.
Essentially, it boils down to a loadRequest:
call to a UIWebView
object, given an URLRequest
built from an NSURL
which references a file URL, for a file in the app bundle, which lives inside a folder that Xcode is including by reference. Phew.
The leak is intermittent but still happens ~75% of the time (in about 20 tests it happened about 15 times). It only happens on the device -- this does not leak in the simulator. I am testing targeting both iPhone OS 3.1.2 and 3.1.3, on an original (1st Gen) iPod Touch that is using iPhone OS 3.1.3.
To reproduce, just create a project from scratch. Add a UIWebView
to the RootViewController
's .xib, hook it up via IBOutlet
. In the Finder, create a folder named "html" inside your project's folder. Inside that folder, create a file named "dummy.html" that has the word "Test" in it. (Does not need to be valid HTML.) Then add the html folder to your project in Xcode by choosing "Create Folder References for any added folders"
Add the following to viewDidLoad
NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
NSString* filePath = [[resourcePath stringByAppendingPathComponent:@"html"] stringByAppendingPathComponent:@"dummy.html"];
NSURL* url = [[NSURL alloc] initFileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:url]; // <-- this creates the leak!
[browserView loadRequest:request];
[url release];
I've tried everything from setting delegate for the UIWebView
and implementing UIWebViewDelegate
, to not setting a delegate in IB, to not setting a delegate in IB and explicitly setting the web view's delegate
property to nil, to using alloc
/init
instead of getting autoreleased NSURLRequest
s (and/or NSURL
s)...
I tried the answer to a similar question (setting the shared URL cache to empty) and that did not help.
Can anyone help?
© Stack Overflow or respective owner