ReactiveCircus / FlowBinding

Kotlin Coroutines Flow binding APIs for Android's platform and unbundled UI widgets, inspired by RxBinding.
https://reactivecircus.github.io/FlowBinding/
Apache License 2.0
900 stars 42 forks source link

LeakCanary shows leaks on standard usage #106

Closed jakoss closed 4 years ago

jakoss commented 4 years ago

Hi,

LeakCanary just showed me this: image

It seems like the root of the leak is the lifecycle registry: image

Do you an idea why this is happening?

The code that caused that is:

binding.goBtn.clicks()
        .onEach { navigateToAnotherFragment() }
        .launchIn(lifecycleScope)
ychescale9 commented 4 years ago

In a Fragment you should use viewLifecycleOwner.lifecycleScope instead of lifecycleScope. That's the only issue as far as I can see.

BTW the full leakcanary stacktrace is also available in logcat so it'd be easier to share that instead of screenshots 😄 .

Please let me know if that fixes the leak for you.

jakoss commented 4 years ago

Wow, didn't know that viewLifecycleOwner has it's own coroutine scope. I learned something new, that's always good.

I can confirm that this indeed solves the issue