Ensure no memory leaks caused by image download completion blocks

This commit is contained in:
Justin Mazzocchi 2021-04-04 12:34:19 -07:00
parent 47a43e6cb4
commit 36b618c03d
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 6 additions and 6 deletions

View file

@ -190,13 +190,13 @@ private extension EditAttachmentViewController {
SDWebImageManager.shared.loadImage(
with: viewModel.attachment.url.url,
options: [],
progress: nil) { image, _, _, _, _, _ in
guard let cgImage = image?.cgImage else { return }
progress: nil) { [weak self] image, _, _, _, _, _ in
guard let self = self, let cgImage = image?.cgImage else { return }
self.detectText(cgImage: cgImage)
.sink { [weak self] in
.sink {
if case let .failure(error) = $0 {
self?.present(alertItem: .init(error: error))
self.present(alertItem: .init(error: error))
}
} receiveValue: { [weak self] in
guard let self = self else { return }

View file

@ -140,11 +140,11 @@ final class ImageViewController: UIViewController {
}
imageView.sd_setImage(with: viewModel.attachment.url.url,
placeholderImage: placeholderImage) { _, error, _, _ in
placeholderImage: placeholderImage) { [weak self] _, error, _, _ in
if error != nil {
let alertItem = AlertItem(error: ImageError.unableToLoad)
self.present(alertItem: alertItem)
self?.present(alertItem: alertItem)
}
}
case .gifv: