mirror of
https://github.com/HackPlan/AsyncDisplayKit.git
synced 2026-04-23 03:20:39 +08:00
Dispatch deallocation of UIImage on background thread
Destruction of bigger images in ASNetworkImageNode on the main thread can be expensive and can take some time, so we dispatch onto a background queue to actually dealloc.
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#import "ASPINRemoteImageDownloader.h"
|
||||
#endif
|
||||
|
||||
static const CGSize kMinReleaseImageOnBackgroundSize = {20.0, 20.0};
|
||||
|
||||
@interface ASNetworkImageNode ()
|
||||
{
|
||||
ASDN::RecursiveMutex _lock;
|
||||
@@ -228,8 +230,7 @@
|
||||
ASDN::MutexLocker l(_lock);
|
||||
|
||||
[self _cancelImageDownload];
|
||||
self.image = _defaultImage;
|
||||
_imageLoaded = NO;
|
||||
[self _clearImage];
|
||||
if (_cacheSupportsClearing) {
|
||||
[_cache clearFetchedImageFromCacheWithURL:_URL];
|
||||
}
|
||||
@@ -248,6 +249,25 @@
|
||||
|
||||
#pragma mark - Private methods -- only call with lock.
|
||||
|
||||
- (void)_clearImage
|
||||
{
|
||||
// Destruction of bigger images on the main thread can be expensive
|
||||
// and can take some time, so we dispatch onto a bg queue to
|
||||
// actually dealloc.
|
||||
UIImage *image = self.image;
|
||||
CGSize imageSize = image.size;
|
||||
BOOL shouldReleaseImageOnBackgroundThread = imageSize.width > kMinReleaseImageOnBackgroundSize.width ||
|
||||
imageSize.height > kMinReleaseImageOnBackgroundSize.height;
|
||||
if (shouldReleaseImageOnBackgroundThread) {
|
||||
__block UIImage *blockImage = image;
|
||||
ASPerformBlockOnBackgroundThread(^{
|
||||
blockImage = nil;
|
||||
});
|
||||
}
|
||||
self.image = _defaultImage;
|
||||
_imageLoaded = NO;
|
||||
}
|
||||
|
||||
- (void)_cancelImageDownload
|
||||
{
|
||||
if (!_downloadIdentifier) {
|
||||
|
||||
Reference in New Issue
Block a user