I run the instruments tool and get some Memory Leaks and i don´t know how to handle this. I´m using ARC!
This is my Code:
+ (MARequest *)requestImageThumb:(NSString *)imageName
object:(NSInteger)objectId {
NSString* urlString = [NSString stringWithFormat:@"%@/%@", kBaseImageThumbURL, imageName];
LogTrace(@"Creating image thumb request for file %@", imageName);
//Here starts the leak!!
return [MARequest createWithURL:[NSURL URLWithString:urlString]
type:REQUEST_TYPE_GET_IMAGE];
}
+ (MARequest *)createWithURL:(NSURL *)url
type:(NSInteger)type {
MARequest* r = [[MARequest alloc] init];
r.url = url;
r.requestType = type;
r.responseData = [[NSMutableData alloc] init];
r.connection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:r.url]
delegate:r
startImmediately:NO];
return r;
}
And here my NSURLConnectionDelegate
#pragma mark - NSURLConnectionDelegate
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
LogTrace(@"request %@: didReceiveResponse", self.url);
[self.responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
LogTrace(@"request %@: didReceiveData, %d bytes", self.url, data.length);
[self.responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
LogTrace(@"request %@: didFailWithError: %@", self.url, [error description]);
self.connection = nil;
self.failed = YES;
[self invokeAction];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
LogTrace(@"request %@: connectionDidFinishLoading, %d bytes", self.url, [self.responseData length]);
self.connection = nil;
[self invokeAction];
}
EDIT:
I changed my Code to this now, but sadly it still gives me a Memory Leak....
+ (MARequest *)requestImageThumb:(NSString *)imageName
object:(NSInteger)objectId {
NSString* urlString = [NSString stringWithFormat:@"%@/%@", kBaseImageThumbURL, imageName];
LogTrace(@"Creating image thumb request for file %@", imageName);
return [MARequest requestWithURL:[NSURL URLWithString:urlString]
type:REQUEST_TYPE_GET_IMAGE];
}
+ (MARequest *)requestWithURL:(NSURL *)url
type:(NSInteger)type {
MARequest* r = [[MARequest alloc] init];
r.url = url;
r.requestType = type;
r.responseData = [[NSMutableData alloc] init];
r.connection = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:r.url]
delegate:r
startImmediately:NO];
return r;
}