I got a UIWebView in my project with DSBezelActivityView but it seems to have a memory leak. I use the DSBezelActivityView for when the page is loading. It works as it should beside the memory leak. How do I solve this memory leak?
I used this code: http://www.dejal.com/developer/dsactivityview
This is what analyzer says: Object leaked: allocated object is not referenced later in this execution path and has a retain count of +1 Method returns an Objective-C object with a +1 retain count
- (void)viewDidLoad
{
NSString *urlAddress = [NSString stringWithFormat:@"http://www.google.be"];
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webView.delegate = self;
//Load the request in the UIWebView.
[webView loadRequest:requestObj];
[super viewDidLoad];
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
[DSBezelActivityView newActivityViewForView:aiv withLabel:@"Laden..." width:90];
NSLog(@"werkt dit");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[DSBezelActivityView removeView];
}
Seems like you're leaking the object returned by newActivityViewForView:withLabel:width
.
According to Apple's documentation:
You own any object you create
You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy).
So you need to release the object at a proper moment, I think it is the webViewDidFinishLoad:
. Your code should be something like these:
- (void)webViewDidStartLoad:(UIWebView *)webView {
DSBezelActivityView *bezelActivityView = [DSBezelActivityView newActivityViewForView:aiv withLabel:@"Laden..." width:90];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[DSBezelActivityView removeView];
[bezelActivityView release];
bezelActivityView = nil;
}
I don't this DSBezelActivityView
class so my answer is based on the Cocoa Memory Management Conventions. Keep in mind that could have created a method starting with new that does not follow the convention.