Search code examples
iphoneobjective-cmemory-leaksasihttprequestobjective-c-blocks

Memory leak using ASIHTTPRequest block


I am using ASIHTTPRequest as defined in the example:

  __block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setCompletionBlock:^{
    // Use when fetching text data
    NSString *responseString = [request responseString];//Memory leak here!!!
    NSLog(responseString);
   [connectionDelegate performSelector:succeededAction withObject:responseString];
}];

I keep getting a memory leak here and I have no idea why... (memory leak using instruments)

Any ideas???


Solution

  • The code you posted is fine and won't leak memory - the memory leak must be inside the code called here:

    [connectionDelegate performSelector:succeededAction withObject:responseString];
    

    That succeededAction function or something it calls must be retaining responseString and not releasing it later.