From 325e028524b44df1d0c85835693c96be8bbe3f65 Mon Sep 17 00:00:00 2001 From: Ali <> Date: Tue, 26 May 2020 22:17:36 +0400 Subject: [PATCH] Fix memory leak --- submodules/AccountContext/Sources/ChatController.swift | 2 ++ submodules/ChatListUI/Sources/ChatListController.swift | 2 +- submodules/TelegramUI/Sources/ChatController.swift | 5 +++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/submodules/AccountContext/Sources/ChatController.swift b/submodules/AccountContext/Sources/ChatController.swift index f523dc2eba..0fc0720950 100644 --- a/submodules/AccountContext/Sources/ChatController.swift +++ b/submodules/AccountContext/Sources/ChatController.swift @@ -364,6 +364,8 @@ public enum ChatPresentationInputQueryResult: Equatable { } } +public let ChatControllerCount = Atomic(value: 0) + public protocol ChatController: ViewController { var chatLocation: ChatLocation { get } var canReadHistory: ValuePromise { get } diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 7626df6459..eadda47800 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -1065,7 +1065,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, return } - #if false && DEBUG + #if true && DEBUG DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.0, execute: { [weak self] in guard let strongSelf = self else { return diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index f554632a2d..0c53b4e3e6 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -140,8 +140,6 @@ private func calculateSlowmodeActiveUntilTimestamp(account: Account, untilTimest } } -let ChatControllerCount = Atomic(value: 0) - public final class ChatControllerImpl: TelegramBaseController, ChatController, GalleryHiddenMediaTarget, UIDropInteractionDelegate { private var validLayout: ContainerViewLayout? @@ -542,6 +540,9 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G strongSelf.controllerInteraction?.addContact(phoneNumber) } }, storeMediaPlaybackState: { [weak self] messageId, timestamp in + guard let strongSelf = self else { + return + } var storedState: MediaPlaybackStoredState? if let timestamp = timestamp { storedState = MediaPlaybackStoredState(timestamp: timestamp, playbackRate: .x1)