From 4383e9ab2bf03ad100ddd17507a86e37217a2815 Mon Sep 17 00:00:00 2001 From: Ryan Fitzgerald Date: Thu, 9 Jul 2015 12:31:32 -0400 Subject: [PATCH] releasing downloaded image when multiplex image node exits render range --- AsyncDisplayKit/ASMultiplexImageNode.mm | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/AsyncDisplayKit/ASMultiplexImageNode.mm b/AsyncDisplayKit/ASMultiplexImageNode.mm index 0bc9c6e8f8..d32d3be061 100644 --- a/AsyncDisplayKit/ASMultiplexImageNode.mm +++ b/AsyncDisplayKit/ASMultiplexImageNode.mm @@ -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