I am using ARC and in one method I alloc an operation object. Will that cause a memory leak? If yes where should I set it to nil? Inside the completion blocks or after the [operation start]; ?
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
// success downloading file
// Do something
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// error downloading file
// Do something else
}];
[operation start];
No leak. It’s just fine. However, typically, referring to
operationwithin the block will cause a retain cycle. But it looks like that API anticipated this for you and passes a usable copy. I guess you can assume that theoperationblock parameter is safe to refer to.Typically if you need to refer to the block owner within the block, you would declare an unretained copy and refer to that instead…