From 42f9d19ee9c9b1956ed9e9719fd6a4b16534343c Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 20 Sep 2020 11:28:18 -0400 Subject: [PATCH] Fix memory leak in attachment container view --- .../Views/Attachments/AttachmentsContainerView.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Tusker/Views/Attachments/AttachmentsContainerView.swift b/Tusker/Views/Attachments/AttachmentsContainerView.swift index 90928ab8..6c7bb080 100644 --- a/Tusker/Views/Attachments/AttachmentsContainerView.swift +++ b/Tusker/Views/Attachments/AttachmentsContainerView.swift @@ -57,12 +57,12 @@ class AttachmentsContainerView: UIView { attachmentViews.allObjects.forEach { $0.removeFromSuperview() } attachmentViews.removeAllObjects() moreView?.removeFromSuperview() + + var accessibilityElements = [Any]() if attachments.count > 0 { self.isHidden = false - var accessibilityElements = [Any]() - switch attachments.count { case 1: let attachmentView = createAttachmentView(index: 0, hSize: .full, vSize: .full) @@ -215,12 +215,15 @@ class AttachmentsContainerView: UIView { accessibilityElements.append(topRight) accessibilityElements.append(bottomLeft) accessibilityElements.append(moreView) + } - - self.accessibilityElements = accessibilityElements } else { self.isHidden = true } + + // Make sure accessibilityElements is set every time the UI is updated, otherwise it holds + // on to strong references to the old set of attachment views + self.accessibilityElements = accessibilityElements contentHidden = Preferences.shared.blurAllMedia || status.sensitive }