Object 0x3d58870 of class NSCFString autoreleased with no pool in place - just leaking
I'm receiving this memory warning for almost all variables used in the following function
- (void) backgroundTask {
c= [array1 count];
if (c == 0){
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"ERROR" message:@"Chose an image to upload!!!" delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil];
[alert show];
[alert release];
}
else {
for(k==0;k<c;k++){
[uploading startAnimating];
upload = [array1 objectAtIndex:0];
NSData *imageData = UIImageJPEGRepresentation(upload, .9);
NSString *urlString = @"http://fileserver.colormailer.com/fileserver/photoService?method=addPhoto&description=testingupload&albumId=nithinalbum&userId=123nithin&sid=12345678&title=image125";
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request addValue:contentType forHTTPHeaderField:@"Content-Type"];
NSMutableData *body = [NSMutableData data];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"userfile\"; filename=\".jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imageData]];
[body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
msg = [[NSString alloc]initWithFormat:@"Upload number %d",a];
NSLog(msg);
NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(returnString);
a++;
[returnString release];
[array1 removeObjectAtIndex:0];
}
[uploading stopAnimating];
if(c == 1){
msg = [[NSString alloc]initWithFormat: @"1 image uploaded"];
}
else{
msg = [[NSString alloc]initWithFormat: @"%d images uploaded",c];
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"upload success" message:msg delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil];
[alert show];
[msg release];
[alert release];
}
}
I'm calling this function as, - (IBAction)pushUpload { [self performSelectorInBackground:@selector(backgroundTask) withObject:nil]; }
When i used the tasks inside the former function, directly in the Action method, there were no problem, but it came for this step. These(the above said warnings) are shown in the console. They come for NSData, NSString,NSMutableArray, and everything i've initiated in this function.. pls help