Added new clearDelegatesAndCancel method
Fix leak in iPad sample
Showing
3 changed files
with
43 additions
and
3 deletions
@@ -583,7 +583,8 @@ typedef void (^ASIDataBlock)(NSData *data); | @@ -583,7 +583,8 @@ typedef void (^ASIDataBlock)(NSData *data); | ||
583 | // Run request in the background | 583 | // Run request in the background |
584 | - (void)startAsynchronous; | 584 | - (void)startAsynchronous; |
585 | 585 | ||
586 | - | 586 | +// Clears all delegates and blocks, then cancels the request |
587 | +- (void)clearDelegatesAndCancel; | ||
587 | 588 | ||
588 | #pragma mark HEAD request | 589 | #pragma mark HEAD request |
589 | 590 |
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | #import "ASIDataCompressor.h" | 24 | #import "ASIDataCompressor.h" |
25 | 25 | ||
26 | // Automatically set on build | 26 | // Automatically set on build |
27 | -NSString *ASIHTTPRequestVersion = @"v1.7-137 2010-11-10"; | 27 | +NSString *ASIHTTPRequestVersion = @"v1.7-139 2010-11-13"; |
28 | 28 | ||
29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; | 29 | NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain"; |
30 | 30 | ||
@@ -375,36 +375,58 @@ static NSOperationQueue *sharedQueue = nil; | @@ -375,36 +375,58 @@ static NSOperationQueue *sharedQueue = nil; | ||
375 | NSMutableArray *blocks = [NSMutableArray array]; | 375 | NSMutableArray *blocks = [NSMutableArray array]; |
376 | if (completionBlock) { | 376 | if (completionBlock) { |
377 | [blocks addObject:completionBlock]; | 377 | [blocks addObject:completionBlock]; |
378 | + [completionBlock release]; | ||
379 | + completionBlock = nil; | ||
378 | } | 380 | } |
379 | if (failureBlock) { | 381 | if (failureBlock) { |
380 | [blocks addObject:failureBlock]; | 382 | [blocks addObject:failureBlock]; |
383 | + [failureBlock release]; | ||
384 | + failureBlock = nil; | ||
381 | } | 385 | } |
382 | if (startedBlock) { | 386 | if (startedBlock) { |
383 | [blocks addObject:startedBlock]; | 387 | [blocks addObject:startedBlock]; |
388 | + [startedBlock release]; | ||
389 | + startedBlock = nil; | ||
384 | } | 390 | } |
385 | if (headersReceivedBlock) { | 391 | if (headersReceivedBlock) { |
386 | [blocks addObject:headersReceivedBlock]; | 392 | [blocks addObject:headersReceivedBlock]; |
393 | + [headersReceivedBlock release]; | ||
394 | + headersReceivedBlock = nil; | ||
387 | } | 395 | } |
388 | if (bytesReceivedBlock) { | 396 | if (bytesReceivedBlock) { |
389 | [blocks addObject:bytesReceivedBlock]; | 397 | [blocks addObject:bytesReceivedBlock]; |
398 | + [bytesReceivedBlock release]; | ||
399 | + bytesReceivedBlock = nil; | ||
390 | } | 400 | } |
391 | if (bytesSentBlock) { | 401 | if (bytesSentBlock) { |
392 | [blocks addObject:bytesSentBlock]; | 402 | [blocks addObject:bytesSentBlock]; |
403 | + [bytesSentBlock release]; | ||
404 | + bytesSentBlock = nil; | ||
393 | } | 405 | } |
394 | if (downloadSizeIncrementedBlock) { | 406 | if (downloadSizeIncrementedBlock) { |
395 | [blocks addObject:downloadSizeIncrementedBlock]; | 407 | [blocks addObject:downloadSizeIncrementedBlock]; |
408 | + [downloadSizeIncrementedBlock release]; | ||
409 | + downloadSizeIncrementedBlock = nil; | ||
396 | } | 410 | } |
397 | if (uploadSizeIncrementedBlock) { | 411 | if (uploadSizeIncrementedBlock) { |
398 | [blocks addObject:uploadSizeIncrementedBlock]; | 412 | [blocks addObject:uploadSizeIncrementedBlock]; |
413 | + [uploadSizeIncrementedBlock release]; | ||
414 | + uploadSizeIncrementedBlock = nil; | ||
399 | } | 415 | } |
400 | if (dataReceivedBlock) { | 416 | if (dataReceivedBlock) { |
401 | [blocks addObject:dataReceivedBlock]; | 417 | [blocks addObject:dataReceivedBlock]; |
418 | + [dataReceivedBlock release]; | ||
419 | + dataReceivedBlock = nil; | ||
402 | } | 420 | } |
403 | if (proxyAuthenticationNeededBlock) { | 421 | if (proxyAuthenticationNeededBlock) { |
404 | [blocks addObject:proxyAuthenticationNeededBlock]; | 422 | [blocks addObject:proxyAuthenticationNeededBlock]; |
423 | + [proxyAuthenticationNeededBlock release]; | ||
424 | + proxyAuthenticationNeededBlock = nil; | ||
405 | } | 425 | } |
406 | if (authenticationNeededBlock) { | 426 | if (authenticationNeededBlock) { |
407 | [blocks addObject:authenticationNeededBlock]; | 427 | [blocks addObject:authenticationNeededBlock]; |
428 | + [authenticationNeededBlock release]; | ||
429 | + authenticationNeededBlock = nil; | ||
408 | } | 430 | } |
409 | [[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]]; | 431 | [[self class] performSelectorOnMainThread:@selector(releaseBlocks:) withObject:blocks waitUntilDone:[NSThread isMainThread]]; |
410 | } | 432 | } |
@@ -648,6 +670,23 @@ static NSOperationQueue *sharedQueue = nil; | @@ -648,6 +670,23 @@ static NSOperationQueue *sharedQueue = nil; | ||
648 | [self performSelector:@selector(cancelOnRequestThread) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; | 670 | [self performSelector:@selector(cancelOnRequestThread) onThread:[[self class] threadForRequest:self] withObject:nil waitUntilDone:NO]; |
649 | } | 671 | } |
650 | 672 | ||
673 | +- (void)clearDelegatesAndCancel | ||
674 | +{ | ||
675 | + [[self cancelledLock] lock]; | ||
676 | + | ||
677 | + // Clear delegates | ||
678 | + [self setDelegate:nil]; | ||
679 | + [self setQueue:nil]; | ||
680 | + [self setDownloadProgressDelegate:nil]; | ||
681 | + [self setUploadProgressDelegate:nil]; | ||
682 | + | ||
683 | + // Clear blocks | ||
684 | + [self releaseBlocksOnMainThread]; | ||
685 | + | ||
686 | + [[self cancelledLock] unlock]; | ||
687 | + [self cancel]; | ||
688 | +} | ||
689 | + | ||
651 | 690 | ||
652 | - (BOOL)isCancelled | 691 | - (BOOL)isCancelled |
653 | { | 692 | { |
@@ -1891,7 +1930,6 @@ static NSOperationQueue *sharedQueue = nil; | @@ -1891,7 +1930,6 @@ static NSOperationQueue *sharedQueue = nil; | ||
1891 | } | 1930 | } |
1892 | #if NS_BLOCKS_AVAILABLE | 1931 | #if NS_BLOCKS_AVAILABLE |
1893 | if(completionBlock){ | 1932 | if(completionBlock){ |
1894 | - __block ASIHTTPRequest *blockCopy = self; | ||
1895 | completionBlock(); | 1933 | completionBlock(); |
1896 | } | 1934 | } |
1897 | #endif | 1935 | #endif |
-
Please register or login to post a comment