Fix retain cycle causing leak for backgroundPolicy RKRequestBackgroundPolicyContinue. closes #548

This commit is contained in:
Blake Watters
2012-03-12 18:50:33 -04:00
parent 995c30907b
commit 749c6e389f

View File

@@ -502,14 +502,16 @@ RKRequestMethod RKRequestMethodTypeFromName(NSString *methodName) {
RKLogInfo(@"Beginning background task to perform processing...");
// Fork a background task for continueing a long-running request
__block RKRequest* weakSelf = self;
__block id<RKRequestDelegate> weakDelegate = _delegate;
_backgroundTaskIdentifier = [app beginBackgroundTaskWithExpirationHandler:^{
RKLogInfo(@"Background request time expired, canceling request.");
[self cancelAndInformDelegate:NO];
[self cleanupBackgroundTask];
[weakSelf cancelAndInformDelegate:NO];
[weakSelf cleanupBackgroundTask];
if ([_delegate respondsToSelector:@selector(requestDidTimeout:)]) {
[_delegate requestDidTimeout:self];
if ([weakDelegate respondsToSelector:@selector(requestDidTimeout:)]) {
[weakDelegate requestDidTimeout:weakSelf];
}
}];