tags:

views:

133

answers:

1

i have the following method

-(void)request
{
    responseData = [[NSMutableData data] retain];
    NSString *post =  [NSString stringWithFormat:@"id=%d&a_id=&d",1,1];
    NSLog(@"%@",post);
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];

    request = [[NSMutableURLRequest alloc] init];

    [request setURL:[NSURL URLWithString:kWebURL@"/req/request.php"]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    [request setHTTPBody:postData];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];

    [postLength release];
    [postData release];
}

-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [connection release];   
}

My problem is that there is a leak with the nsmutableurlrequest object. I think i should release it somewhere, but when i try to do so, i get an exec_bad_access. Whereever i try to release it i get that error at the end of the connectionDidFinishLoading method.

EDIT: It looks like i can either release the NSURLConnection object OR the NSMutableURLConnection object.

If i try to remove both of them when i should, i get an exec_bad_access

+1  A: 

I believe your problem is with your releasing of postLength and postData. You didn't allocate either of these, but created them with convenience methods. You should take those two lines out, and then you should be okay to release your NSMutableURLRequest.

Ben Gottlieb
Yep, looks like it had to do with the crash. Don't know why i was doing that... i saw the code posted around somewhere and used it without thinking... Thank you so much!
pabloruiz55