diff --git a/SDImageCache.m b/SDImageCache.m index b79c9915..b66fbba0 100644 --- a/SDImageCache.m +++ b/SDImageCache.m @@ -75,9 +75,9 @@ static SDImageCache *instance; - (void)dealloc { - SDWIRelease(memCache); - SDWIRelease(diskCachePath); - SDWIRelease(cacheInQueue); + SDWISafeRelease(memCache); + SDWISafeRelease(diskCachePath); + SDWISafeRelease(cacheInQueue); [[NSNotificationCenter defaultCenter] removeObserver:self]; diff --git a/SDWebImageCompat.h b/SDWebImageCompat.h index c15e1704..b63dacb4 100644 --- a/SDWebImageCompat.h +++ b/SDWebImageCompat.h @@ -28,7 +28,8 @@ #define SDWIRetain(__v) ([__v retain]); #define SDWIReturnRetained SDWIRetain -#define SDWIRelease(__v) ([__v release], __v = nil); +#define SDWIRelease(__v) ([__v release]); +#define SDWISafeRelease(__v) ([__v release], __v = nil); #define SDWISuperDealoc [super dealloc]; #define SDWIWeak @@ -41,6 +42,7 @@ #define SDWIReturnRetained(__v) (__v) #define SDWIRelease(__v) +#define SDWISafeRelease(__v) (__v = nil); #define SDWISuperDealoc #define SDWIWeak __unsafe_unretained @@ -70,7 +72,7 @@ NS_INLINE UIImage *SDScaledImageForPath(NSString *path, NSData *imageData) } UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp]; - SDWIRelease(image) + SDWISafeRelease(image) image = scaledImage; } diff --git a/SDWebImageDecoder.m b/SDWebImageDecoder.m index e747de68..1eecee05 100644 --- a/SDWebImageDecoder.m +++ b/SDWebImageDecoder.m @@ -76,7 +76,7 @@ static SDWebImageDecoder *sharedInstance; - (void)dealloc { - SDWIRelease(imageDecodingQueue); + SDWISafeRelease(imageDecodingQueue); SDWISuperDealoc; } diff --git a/SDWebImageDownloader.m b/SDWebImageDownloader.m index 1fa49f39..2dc493b5 100644 --- a/SDWebImageDownloader.m +++ b/SDWebImageDownloader.m @@ -153,10 +153,10 @@ NSString *const SDWebImageDownloadStopNotification = @"SDWebImageDownloadStopNot - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; - SDWIRelease(url); - SDWIRelease(connection); - SDWIRelease(imageData); - SDWIRelease(userInfo); + SDWISafeRelease(url); + SDWISafeRelease(connection); + SDWISafeRelease(imageData); + SDWISafeRelease(userInfo); SDWISuperDealoc; } diff --git a/SDWebImageManager.m b/SDWebImageManager.m index b518db58..b6f9bb49 100644 --- a/SDWebImageManager.m +++ b/SDWebImageManager.m @@ -46,12 +46,12 @@ static SDWebImageManager *instance; - (void)dealloc { - SDWIRelease(downloadDelegates); - SDWIRelease(downloaders); - SDWIRelease(cacheDelegates); - SDWIRelease(cacheURLs); - SDWIRelease(downloaderForURL); - SDWIRelease(failedURLs); + SDWISafeRelease(downloadDelegates); + SDWISafeRelease(downloaders); + SDWISafeRelease(cacheDelegates); + SDWISafeRelease(cacheURLs); + SDWISafeRelease(downloaderForURL); + SDWISafeRelease(failedURLs); SDWISuperDealoc; }