views:

147

answers:

1

Hi Guys,

I am getting the leak at this line in below code" NSData *returnData = [NSURLConnection ..........."

NSURL *finalURL = [NSURL URLWithString:curl]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:finalURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; [theRequest setHTTPMethod:@"GET"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; BOOL enabled = [self getAutoGenerateObject:returnData]; return enabled;

please help me out of this problem. Thank You, Madan Mohan

A: 

You will need to release the returnData. That's why in Apple's examples in 'URL Loading Programming Guide / Using NSURLConnection', the returnData is assigned to an iVar and release in dealloc or connectionDidFinishLoading in the case of Asynchronous communication.

Depending what operation you are performing in you method getAutoGeneratedObject, but in theory it can take ownership there.

You could also mark returnData as autoreleased, but that is not always recommended especially if the response data is large.

NSURL *finalURL = [NSURL URLWithString:curl]; 
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:finalURL 
                                                          cachePolicy:NSURLRequestReloadIgnoringCacheData 
                                                      timeoutInterval:10]; 
[theRequest setHTTPMethod:@"GET"]; 

NSData *returnData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil error:nil]; 

BOOL enabled = [self getAutoGenerateObject:returnData]; 

[returnData release];

return enabled;
ruralcoder