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: Memory leaks on LiveStreamVM #242

Open
wants to merge 1 commit into
base: dev-sdk-main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import dji.v5.manager.datacenter.livestream.settings.RtspSettings
import dji.v5.manager.interfaces.ICameraStreamManager
import dji.v5.utils.common.ContextUtil
import dji.v5.utils.common.DjiSharedPreferencesManager
import java.lang.ref.WeakReference

/**
* ClassName : LiveStreamVM
Expand Down Expand Up @@ -69,10 +70,11 @@ class LiveStreamVM : DJIViewModel() {
}

fun startStream(callback: CommonCallbacks.CompletionCallback?) {
val weakReference = WeakReference(this)
streamManager.startStream(object : CommonCallbacks.CompletionCallback {
override fun onSuccess() {
CallbackUtils.onSuccess(callback)
reset();
weakReference.get()?.reset()
}

override fun onFailure(error: IDJIError) {
Expand All @@ -83,10 +85,11 @@ class LiveStreamVM : DJIViewModel() {
}

fun stopStream(callback: CommonCallbacks.CompletionCallback?) {
val weakReference = WeakReference(this)
streamManager.stopStream(object : CommonCallbacks.CompletionCallback {
override fun onSuccess() {
CallbackUtils.onSuccess(callback)
reset();
weakReference.get()?.reset()
}

override fun onFailure(error: IDJIError) {
Expand Down