From 6f9bb6caa74c47871f125f471a79988a2907ee7c Mon Sep 17 00:00:00 2001 From: Tamim Hossain <132823494+CodeWithTamim@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:35:03 +0600 Subject: [PATCH] Improve RxJava Disposable Handling in V2RayServiceManager (#3767) Refactored the RxJava disposable handling in the V2RayServiceManager to ensure proper disposal when the service stops. This change prevents potential memory leaks by disposing of the disposable only when it's initialized, using a more concise and reliable approach with Kotlin's let function. --- .../main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt index 3c3b2116..9c9ca259 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayServiceManager.kt @@ -428,10 +428,11 @@ object V2RayServiceManager { } private fun stopSpeedNotification() { - if (mDisposable != null) { - mDisposable?.dispose() //stop queryStats + mDisposable?.let { + it.dispose() //stop queryStats mDisposable = null updateNotification(currentConfig?.remarks, 0, 0) } } + }