releasing downloaded image when multiplex image node exits render range

This commit is contained in:
Ryan Fitzgerald
2015-07-09 12:31:32 -04:00
parent 4aed9180d6
commit 4383e9ab2b

View File

@@ -139,6 +139,13 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
*/
- (void)_downloadImageWithIdentifier:(id)imageIdentifier URL:(NSURL *)imageURL completion:(void (^)(UIImage *image, NSError *error))completionBlock;
/**
@abstract Returns a Boolean value indicating whether the downloaded image should be removed when clearing fetched data
@discussion Downloaded image data should only be cleared out if a cache is present
@return YES if an image cache is available; otherwise, NO.
*/
- (BOOL)_shouldClearFetchedImageData;
@end
@implementation ASMultiplexImageNode
@@ -173,11 +180,15 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
}
}
- (void)displayWillStart
- (void)clearFetchedData
{
[super displayWillStart];
[self fetchData];
[super clearFetchedData];
if ([self _shouldClearFetchedImageData]) {
// setting this to nil makes the node fetch images the next time its display starts
_loadedImageIdentifier = nil;
self.image = nil;
}
}
- (void)fetchData
@@ -626,4 +637,8 @@ typedef void(^ASMultiplexImageLoadCompletionBlock)(UIImage *image, id imageIdent
[self _loadNextImage];
}
- (BOOL)_shouldClearFetchedImageData {
return _cache != nil;
}
@end