For the program below i get the following error-
Potential leak of an object allocated on line 50.
Line 50 points to this line–
self.receivedData = [[NSMutableData data] retain];
I tried to release receiveData after this statement but that gives me an error “object sent autorelease too many times.” I am not sure if i am doing it the right way.Please help!
- (void)viewDidLoad {
NSURLRequest *theRequest =
[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://{your ip}:8080/activiti-rest/service/process-definitions?start=0&size=10&sort=id&order=asc"] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
self.receivedData = [[NSMutableData data] retain];
} else {
UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[connectFailMessage show];
[connectFailMessage release];
}
[theConnection autorelease];
}
Edit : In the header file it is declared as @property(nonatomic,assign) NSMutableData *receivedData;
New
It works after i removed this line[theConnection autorelease]. I kept the assign property as is in the header file and added the [self.receiveData release] like you asked.It did not work earlier because i kept this line [theConnection autorelease].I added it because i was wondering if i have to release theConnection object also.Can you please explain why that doesn’t have to released?It is not released anywhere in the code and it still works??
Without seeing more code, the analyzer may potentially be confused.
Where is your balancing -release? In -dealloc?
Why is this property not
retainin the first place?You should be releasing the object in -dealloc, too. And you still haven’t answered why the object is not
retain— that seems distinctly odd.