views:

81

answers:

2

Hello,

I have the following code:

    + (BOOL)updateStatus:(NSString *)status forUsername:(NSString *)username withPassword:(NSString *)password {

NSURL *loginURL = [NSURL URLWithString:@"XYZ"];
ASIFormDataRequest *loginRequest = [[ASIFormDataRequest requestWithURL:loginURL] retain]; 
[loginRequest setPostValue:@VALUE forKey:@"SOME_KEY"]; 
[loginRequest setPostValue:username forKey:@"username"]; 
[loginRequest setPostValue:password forKey:@"password"];  
[loginRequest startSynchronous]; 

int loginStatusCode = [loginRequest responseStatusCode];
[loginRequest release];

if (loginStatusCode == 200) { //if we were able to login
    NSURL *updateURL = [NSURL URLWithString:@"ABC"];
    ASIFormDataRequest *updateRequest = [[ASIFormDataRequest requestWithURL:updateURL] retain]; 
    [updateRequest setPostValue:@VALUE forKey:@"SOME_KEY"]; 
    [updateRequest setPostValue:VALUE   forKey:@"SOME_KEY"];
    [updateRequest setPostValue:@"VALUE" forKey:@"SOME_KEY"]; 
    [updateRequest startSynchronous]; 

    int statusCode = [updateRequest responseStatusCode];
    [updateRequest release];

    NSURL *logoutURL = [NSURL URLWithString:@"ABC"];
    ASIFormDataRequest *logoutRequest = [ASIFormDataRequest requestWithURL:logoutURL]; 
    [logoutRequest setPostValue:VALUE forKey:@"KEY"]; 
    [logoutRequest startSynchronous]; 

    [logoutRequest release];
    if (statusCode == 200) { /
        return YES;
    } else {
        return NO;
    }
} else {
    return NO; 
}
}

I run the code on the Simulator with Instruments and it reports the following leak: alt text pointing to the following line:

NSURL *loginURL = [NSURL URLWithString:@"XYZ"];

I am pretty sure that I don't have to release NSURL (due to the convention that I need to release only the objects created with init or copy). Am I wrong? or is there something else wrong with the code?

A: 

Why are you releasing logoutRequest? You didn't retain it.

I don't see any problem with your usage of NSURL, they are all autoreleased.

progrmr
+1  A: 

From what I can tell you are correct. You should not need to release loginURL.

However I notice that elsewhere in the code you do overrelease logoutRequest.

// Note no retain of logoutRequest here as is done elsewhere
ASIFormDataRequest *logoutRequest = [ASIFormDataRequest requestWithURL:logoutURL];   
// ... 
[logoutRequest release];
Lawrence Johnston
Oh, yes, I added the release code because Instruments showed me another leak related to logoutRequest and loginRequest.Any ideas why Intruments shows me the leak?
Jakub