From 82faab82d3b09fa6e051a95c44d8141dc768aa20 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Wed, 28 Nov 2012 00:39:58 +0100 Subject: [PATCH] Do not capture self in operations in categories --- SDWebImage/MKAnnotationView+WebCache.m | 5 ++++- SDWebImage/UIButton+WebCache.m | 10 ++++++++-- SDWebImage/UIImageView+WebCache.m | 7 +++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/SDWebImage/MKAnnotationView+WebCache.m b/SDWebImage/MKAnnotationView+WebCache.m index 0c9dd759..f0d2c1ce 100644 --- a/SDWebImage/MKAnnotationView+WebCache.m +++ b/SDWebImage/MKAnnotationView+WebCache.m @@ -46,11 +46,14 @@ static char operationKey; if (url) { + __weak MKAnnotationView *wself = self; id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, BOOL fromCache, BOOL finished) { + __strong MKAnnotationView *sself = wself; + if (!sself) return; if (image) { - self.image = image; + sself.image = image; } if (completedBlock && finished) { diff --git a/SDWebImage/UIButton+WebCache.m b/SDWebImage/UIButton+WebCache.m index 717da24f..53c99a5e 100644 --- a/SDWebImage/UIButton+WebCache.m +++ b/SDWebImage/UIButton+WebCache.m @@ -45,11 +45,14 @@ static char operationKey; if (url) { + __weak UIButton *wself = self; id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + __strong UIButton *sself = wself; + if (!sself) return; if (image) { - [self setImage:image forState:state]; + [sself setImage:image forState:state]; } if (completedBlock && finished) { @@ -93,11 +96,14 @@ static char operationKey; if (url) { + __weak UIButton *wself = self; id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + __strong UIButton *sself = wself; + if (!sself) return; if (image) { - [self setBackgroundImage:image forState:state]; + [sself setBackgroundImage:image forState:state]; } if (completedBlock && finished) { diff --git a/SDWebImage/UIImageView+WebCache.m b/SDWebImage/UIImageView+WebCache.m index 4e334d11..01eab545 100644 --- a/SDWebImage/UIImageView+WebCache.m +++ b/SDWebImage/UIImageView+WebCache.m @@ -51,12 +51,15 @@ static char operationKey; if (url) { + __weak UIImageView *wself = self; id operation = [SDWebImageManager.sharedManager downloadWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) { + __strong UIImageView *sself = wself; + if (!sself) return; if (image) { - self.image = image; - [self setNeedsLayout]; + sself.image = image; + [sself setNeedsLayout]; } if (completedBlock && finished) {