Hi,
I have the following method and I think it is leaking. If I print out the retain for the request and connection objects, They are set to be 2. If I release them once again, additionally to the release I already do, the app crashes. As far as i can see 2 - (retain#1)- (retain#2) has to end up to be 0. On the the other hand, I do not understand why the retain of this object is 2 at this moment in the code. I just did create it by alloc/init. How can I do this differently? Any advice? I assume I did missunderstand something here...
Thanks in advance!
MACloop
I have the following method and I think it is leaking. If I print out the retain for the request and connection objects, They are set to be 2. If I release them once again, additionally to the release I already do, the app crashes. As far as i can see 2 - (retain#1)- (retain#2) has to end up to be 0. On the the other hand, I do not understand why the retain of this object is 2 at this moment in the code. I just did create it by alloc/init. How can I do this differently? Any advice? I assume I did missunderstand something here...
Thanks in advance!
MACloop
Code:
#pragma mark connection help Methods
- (void)requestWithUrls{
[receivedDatas removeAllObjects];
[requests removeAllObjects];
for(NSInteger i=0; i< [urls count]; i++){
NSMutableData *aData = [[NSMutableData alloc] init];
[receivedDatas addObject: aData];
[aData release];
NSURLRequest *request = [[NSURLRequest alloc]
initWithURL: [NSURL URLWithString: [urls objectAtIndex:i]]
cachePolicy: NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval: 10];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[requests setObject: [NSNumber numberWithInt: i] forKey:[NSValue valueWithNonretainedObject:connection]];
NSLog(@"connection retainCount:%d", [connection retainCount]);
NSLog(@"request retainCount:%d", [request retainCount]);
[connection release];
[request release];
}
}