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

Memory leaks when Room.connect(url: String, token: String, connectOptions: ConnectOptions? = nil, roomOptions: RoomOptions? = nil) #435

Open
henry-castalk opened this issue Jul 17, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@henry-castalk
Copy link

henry-castalk commented Jul 17, 2024

Steps to Reproduce

Here is how I connect and disconnect a room

  1. Declare the liveKitRoom: Room variable, a method connectToLiveKitRoom() to connect and a method teardownLiveKitRoom() to cleanup after disconnect.
  2. After got the liveStreamUrl?.absoluteString and liveKitRoomToken, I processed the connectToLiveKitRoom() method, and surely call teardownLiveKitRoom() after leaving the screen.
  3. The leaks show in the Instrument screen. According to the stacktrace, the leaks cause at this block of code
static func createPeerConnection(_ configuration: LKRTCConfiguration,
                                     constraints: LKRTCMediaConstraints) -> LKRTCPeerConnection?
    {
        DispatchQueue.liveKitWebRTC.sync { peerConnectionFactory.peerConnection(with: configuration,
                                                                                constraints: constraints,
                                                                                delegate: nil) }
    }
image

Here is my code

private let liveKitRoom: Room = {
    let adaptiveStream = true
    let roomOptions = RoomOptions(adaptiveStream: adaptiveStream)
    let room = Room(roomOptions: roomOptions)
    return room
}()

private func connectToLiveKitRoom() {
    Task { [weak self] in
        guard let self else { return }
        try await liveKitRoom.connect(
            url: liveStreamUrl?.absoluteString ?? "",
            token: liveKitRoomToken ?? ""
        )
    }
}

private func teardownLiveKitRoom() {
    liveKitRoom.remove(delegate: self)
    Task { [liveKitRoom] in
        await Self.mute(liveKitRoom: liveKitRoom)
        await liveKitRoom.disconnect()
    }
}

SDK Version
2.0.5
I tried to upgrade the library from 2.0.5 to 2.0.6, 2.0.7, 2.0.8, 2.0.9, 2.0.10 but the leaks still happen.

iOS/macOS Version
17.5.1

Xcode Version

  • Xcode: Version 15.4 (15F31d)
  • Swift
xcrun swift -version
swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Expected behavior
Leaks doesn't happen

@henry-castalk henry-castalk added the bug Something isn't working label Jul 17, 2024
@hiroshihorie
Copy link
Member

Thanks for the detailed report.
That block of code doesn't seem to retain code, it could be leaking at WebRTC level.

@henry-castalk
Copy link
Author

@hiroshihorie Thanks man. Do you have any suggestion about what I should do to resolve this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants