Skip to content

Commit

Permalink
fix: avoid memory leak on iOS (#4355)
Browse files Browse the repository at this point in the history
* fix: avoid memory leak on iOS

---------

Co-authored-by: Vladimir Vlasov <[email protected]>
  • Loading branch information
vladvlasov256 and Vladimir Vlasov authored Jan 4, 2025
1 parent d31c72f commit 424f4ee
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions ios/Video/ReactNativeVideoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down

0 comments on commit 424f4ee

Please sign in to comment.