fix: avoid memory leak on iOS (#4355)

* fix: avoid memory leak on iOS

---------

Co-authored-by: Vladimir Vlasov <crivlaldo@gmail.com>
This commit is contained in:
Vladimir 2025-01-04 13:47:22 +01:00 committed by GitHub
parent d31c72fc04
commit 424f4eedde
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,33 +6,31 @@
import Foundation import Foundation
public class ReactNativeVideoManager: RNVPlugin { public class ReactNativeVideoManager: RNVPlugin {
private let expectedMaxVideoCount = 10 private let expectedMaxVideoCount = 2
// create a private initializer // create a private initializer
private init() {} private init() {}
public static let shared: ReactNativeVideoManager = .init() public static let shared: ReactNativeVideoManager = .init()
var instanceList: [RCTVideo] = Array() private var instanceCount = 0
var pluginList: [RNVPlugin] = Array() private var pluginList: [RNVPlugin] = Array()
/** /**
* register a new ReactExoplayerViewManager in the managed list * register a new view
*/ */
func registerView(newInstance: RCTVideo) { func registerView(newInstance _: RCTVideo) {
if instanceList.count > expectedMaxVideoCount { if instanceCount > expectedMaxVideoCount {
DebugLog("multiple Video displayed ?") DebugLog("multiple Video displayed ?")
} }
instanceList.append(newInstance) instanceCount += 1
} }
/** /**
* unregister existing ReactExoplayerViewManager in the managed list * unregister existing view
*/ */
func unregisterView(newInstance: RCTVideo) { func unregisterView(newInstance _: RCTVideo) {
if let i = instanceList.firstIndex(of: newInstance) { instanceCount -= 1
instanceList.remove(at: i)
}
} }
/** /**