From d22aeed3f662c2049b76b2e0d13ebad20e4a0d18 Mon Sep 17 00:00:00 2001 From: Xavier Gouchet Date: Mon, 3 Jul 2023 09:33:44 +0200 Subject: [PATCH] Use WeakHashMap to store window keys --- .../internal/vitals/JankStatsActivityLifecycleListener.kt | 5 +++-- detekt_custom.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/vitals/JankStatsActivityLifecycleListener.kt b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/vitals/JankStatsActivityLifecycleListener.kt index 270e2471b0..f47ff46131 100644 --- a/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/vitals/JankStatsActivityLifecycleListener.kt +++ b/dd-sdk-android/src/main/kotlin/com/datadog/android/rum/internal/vitals/JankStatsActivityLifecycleListener.kt @@ -15,6 +15,7 @@ import androidx.metrics.performance.FrameData import androidx.metrics.performance.JankStats import com.datadog.android.v2.api.InternalLogger import java.lang.ref.WeakReference +import java.util.WeakHashMap import java.util.concurrent.TimeUnit /** @@ -26,8 +27,8 @@ internal class JankStatsActivityLifecycleListener( private val jankStatsProvider: JankStatsProvider = JankStatsProvider.DEFAULT ) : ActivityLifecycleCallbacks, JankStats.OnFrameListener { - private val activeWindowsListener = mutableMapOf() - private val activeActivities = mutableMapOf>>() + private val activeWindowsListener = WeakHashMap() + private val activeActivities = WeakHashMap>>() // region ActivityLifecycleCallbacks @MainThread diff --git a/detekt_custom.yml b/detekt_custom.yml index 7ee81990f0..d1214358cc 100644 --- a/detekt_custom.yml +++ b/detekt_custom.yml @@ -613,7 +613,6 @@ datadog: - "kotlin.collections.List.toSet()" - "kotlin.collections.List.withIndex()" - "kotlin.collections.Map.containsKey(kotlin.String)" - - "kotlin.collections.MutableMap.containsKey(android.view.Window)" - "kotlin.collections.Map.filter(kotlin.Function1)" - "kotlin.collections.Map.filterKeys(kotlin.Function1)" - "kotlin.collections.Map.filterValues(kotlin.Function1)" @@ -671,6 +670,7 @@ datadog: - "kotlin.collections.MutableList?.firstOrNull(kotlin.Function1)" - "kotlin.collections.MutableMap.clear()" - "kotlin.collections.MutableMap.containsKey(kotlin.Long)" + - "kotlin.collections.MutableMap.containsKey(android.view.Window)" - "kotlin.collections.MutableMap.filterKeys(kotlin.Function1)" - "kotlin.collections.MutableMap.forEach(kotlin.Function1)" - "kotlin.collections.MutableMap?.forEach(kotlin.Function1)"