Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid memory leak on iOS #4355

Merged
merged 3 commits into from
Jan 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Comment on lines -22 to +23
Copy link
Member

@KrzysztofMoch KrzysztofMoch Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this breaking change? If it is let's add "!" to commit -> fix!: avoid memory leak on iOS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't break the existing API. But the argument is unused so _ makes the linter happy.

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
Loading