Skip to content

Memory leak in LifecycleCoroutineScopeStore #136

@damianw

Description

@damianw

Hi, loved finding your library! I was just contemplating writing something like it until I came across it and it seemed to match perfectly with what I was looking for. I did however come across a few issues that I wanted to flag to see if they're on your radar - notably with LifecycleCoroutineScopeStore.

Each access of LifecycleOwner.lifecycleScope for a distinct Lifecycle (any individual instance of a Fragment, Activity, etc) results in an insertion to map which is never removed, leaking both the Lifecycle key and the LifecycleCoroutineScope value.

A separate issue is that LifecycleCoroutineScopeStore is not thread-safe, because the "get or put" logic as implemented is not atomic. Multiple concurrent invocations of get may return separate instances of LifecycleCoroutineScope, but only one of them will get stored in map. A possible fix would be to use Kotlin's ConcurrentMap.getOrPut or the built-in computeIfAbsent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions