diff --git a/Libraries/Image/RCTImageView.m b/Libraries/Image/RCTImageView.m index b37c897be..104308131 100644 --- a/Libraries/Image/RCTImageView.m +++ b/Libraries/Image/RCTImageView.m @@ -238,8 +238,22 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init) [super didMoveToWindow]; if (!self.window) { - [self clearImage]; - } else if (self.src) { + // Don't keep self alive through the asynchronous dispatch, if the intention was to remove the view so it would + // deallocate. + __weak typeof(self) weakSelf = self; + + dispatch_async(dispatch_get_main_queue(), ^{ + __strong typeof(self) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + + // If we haven't been re-added to a window by this run loop iteration, clear out the image to save memory. + if (!strongSelf.window) { + [strongSelf clearImage]; + } + }); + } else if (!self.image && self.src) { [self reloadImage]; } }