From 424f4eeddea989392e25c52f45a9a0281ead6fe1 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 4 Jan 2025 13:47:22 +0100 Subject: [PATCH] fix: avoid memory leak on iOS (#4355) * fix: avoid memory leak on iOS --------- Co-authored-by: Vladimir Vlasov --- ios/Video/ReactNativeVideoManager.swift | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ios/Video/ReactNativeVideoManager.swift b/ios/Video/ReactNativeVideoManager.swift index 5057b393..77767f9c 100644 --- a/ios/Video/ReactNativeVideoManager.swift +++ b/ios/Video/ReactNativeVideoManager.swift @@ -6,33 +6,31 @@ import Foundation public class ReactNativeVideoManager: RNVPlugin { - private let expectedMaxVideoCount = 10 + private let expectedMaxVideoCount = 2 // create a private initializer private init() {} public static let shared: ReactNativeVideoManager = .init() - var instanceList: [RCTVideo] = Array() - var pluginList: [RNVPlugin] = Array() + private var instanceCount = 0 + private var pluginList: [RNVPlugin] = Array() /** - * register a new ReactExoplayerViewManager in the managed list + * register a new view */ - func registerView(newInstance: RCTVideo) { - if instanceList.count > expectedMaxVideoCount { + func registerView(newInstance _: RCTVideo) { + if instanceCount > expectedMaxVideoCount { DebugLog("multiple Video displayed ?") } - instanceList.append(newInstance) + instanceCount += 1 } /** - * unregister existing ReactExoplayerViewManager in the managed list + * unregister existing view */ - func unregisterView(newInstance: RCTVideo) { - if let i = instanceList.firstIndex(of: newInstance) { - instanceList.remove(at: i) - } + func unregisterView(newInstance _: RCTVideo) { + instanceCount -= 1 } /**