From c8845fe04c1596fe2e7242302bf160bc671910cb Mon Sep 17 00:00:00 2001 From: HUI Date: Tue, 15 Dec 2020 20:03:50 +0800 Subject: [PATCH] fix: `RtcSurfaceView` memory leak --- .gitignore | 1 + RtcSurfaceView.swift | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..9f11b755a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/RtcSurfaceView.swift b/RtcSurfaceView.swift index 2d20efc0c..e5181ec90 100644 --- a/RtcSurfaceView.swift +++ b/RtcSurfaceView.swift @@ -18,13 +18,17 @@ class RtcSurfaceView: UIView { }() private weak var channel: AgoraRtcChannel? + func destroy() { + canvas.view = nil + } + func setData(_ engine: AgoraRtcEngineKit, _ channel: AgoraRtcChannel?, _ uid: Int) { self.channel = channel canvas.channelId = channel?.getId() canvas.uid = UInt(uid) setupVideoCanvas(engine) } - + func resetVideoCanvas(_ engine: AgoraRtcEngineKit) { let canvas = AgoraRtcVideoCanvas() canvas.view = nil @@ -32,14 +36,14 @@ class RtcSurfaceView: UIView { canvas.channelId = self.canvas.channelId canvas.uid = self.canvas.uid canvas.mirrorMode = self.canvas.mirrorMode - + if canvas.uid == 0 { engine.setupLocalVideo(canvas) } else { engine.setupRemoteVideo(canvas) } } - + private func setupVideoCanvas(_ engine: AgoraRtcEngineKit) { if canvas.uid == 0 { engine.setupLocalVideo(canvas) @@ -47,7 +51,7 @@ class RtcSurfaceView: UIView { engine.setupRemoteVideo(canvas) } } - + func setRenderMode(_ engine: AgoraRtcEngineKit, _ renderMode: Int) { canvas.renderMode = AgoraVideoRenderMode(rawValue: UInt(renderMode))! setupRenderMode(engine)