Skip to content
This repository has been archived by the owner on Jul 28, 2020. It is now read-only.

Commit

Permalink
Retain cycle fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
darrylhthomas committed May 10, 2012
1 parent fb9f625 commit eb63512
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
24 changes: 13 additions & 11 deletions AFNetworking/AFHTTPRequestOperation.m
Expand Up @@ -56,30 +56,32 @@ - (id)initWithRequest:(NSURLRequest *)request {
//by default we will use the queue that created the request.
self.callbackQueue = dispatch_get_current_queue();

__weak AFHTTPRequestOperation *weakSelf = self;
super.completionBlock = ^ {
if (_completionBlock) {
_completionBlock(); //call any child completion blocks that may have been passed in that they may want to run
AFHTTPRequestOperation *strongSelf = weakSelf;
if (strongSelf->_completionBlock) {
strongSelf->_completionBlock(); //call any child completion blocks that may have been passed in that they may want to run
}

if ([self isCancelled]) {
if ([strongSelf isCancelled]) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self endBackgroundTask];
[strongSelf endBackgroundTask];
#endif
self.finishedBlock = nil;
strongSelf.finishedBlock = nil;
return;
}

if (self.finishedBlock) {
dispatch_sync(self.callbackQueue, ^(void) {
self.finishedBlock();
if (strongSelf.finishedBlock) {
dispatch_sync(strongSelf.callbackQueue, ^(void) {
strongSelf.finishedBlock();
});
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self endBackgroundTask];
[strongSelf endBackgroundTask];
#endif
self.finishedBlock = nil;
strongSelf.finishedBlock = nil;
} else {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_4_0
[self endBackgroundTask];
[strongSelf endBackgroundTask];
#endif
}
};
Expand Down
3 changes: 2 additions & 1 deletion AFNetworking/AFURLConnectionOperation.m
Expand Up @@ -256,8 +256,9 @@ - (void)setCompletionBlock:(void (^)(void))block {
} else {
__weak id _blockSelf = self;
[super setCompletionBlock:^ {
id strongSelf = _blockSelf;
block();
[_blockSelf setCompletionBlock:nil];
[strongSelf setCompletionBlock:nil];
}];
}
}
Expand Down

0 comments on commit eb63512

Please sign in to comment.