Koin: Activity leaking with interaction between KOIN, ViewModel, and NavHostFragment

Created on 15 Jun 2018  路  8Comments  路  Source: InsertKoinIO/koin

Describe the bug
When injecting a ViewModel(with parameters) with KOIN, an Activity is being leaked through KoinFactory->ViewModel->Fragment->NavHostFragment->NavController->Activity.

To Reproduce

  1. Setup project with the new androidx.Navigation library
  2. Inject ViewModel with parameters to the Fragment
  3. Close app
  4. LeakCanary reports Activity leak for the activity hosting the NavHostFragment.

Expected behavior
No memory leak.

Koin project used and used version (please complete the following information):
koin-core, -android, -android-architecture 0.9.3
androidx.Navigation - 1.0.0-alpha02

Additional context'
LeakCanary report:
https://gist.github.com/trobertsca/c56cb2a87be67b4ad1e54f5f54a44f4c

I'm not 100% sure this is due to KOIN, but my google-fu is failing me.

android accepted issue

Most helpful comment

Awesome! You rock :)

All 8 comments

Can you provide your code sample? Memory leak can also depend on your usage of Koin.

Here's a gist with what I believe are all the relevant files: https://gist.github.com/trobertsca/dd1acd78a0d3e9636893c4258933b1a5

If you need anything more just let me know. (And excuse the code, I'm somewhat new to kotlin+android :) )

Does one of your parameters reference a ViewModel?

No, the only parameters passed with koin would be a Context for the RoomDatabase, the Dao for the Repository, the Repository for ViewModels, and an int for a ViewModel.

@trobertsca could you help me save time, by making a real android project and share it as a public github project?
It will help investigate ;)

Kind of "good news". I reproduced a memory leak with ViewModel & injection parameters :/

I can investigate...

it's fixed. Just need time to release it. Available inkoin-android-viewmodel version 1.0.0-alpha-28
I'm releasing it

Awesome! You rock :)

Was this page helpful?
0 / 5 - 0 ratings