client-sdk-swift
client-sdk-swift copied to clipboard
Memory leaks when Room.connect(url: String, token: String, connectOptions: ConnectOptions? = nil, roomOptions: RoomOptions? = nil)
Steps to Reproduce
Here is how I connect and disconnect a room
- Declare the
liveKitRoom: Roomvariable, a methodconnectToLiveKitRoom()to connect and a methodteardownLiveKitRoom()to cleanup after disconnect. - After got the
liveStreamUrl?.absoluteStringandliveKitRoomToken, I processed theconnectToLiveKitRoom()method, and surely callteardownLiveKitRoom()after leaving the screen. - 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) }
}
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