Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity leaking with interaction between KOIN, ViewModel, and NavHostFragment #149

Closed
trobertsca opened this issue Jun 15, 2018 · 8 comments
Labels
Milestone

Comments

@trobertsca
Copy link

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.

@arnaudgiuliani
Copy link
Member

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

@arnaudgiuliani arnaudgiuliani added question Usage question status:checking currently in analysis - discussion or need more detailed specs labels Jun 16, 2018
@trobertsca
Copy link
Author

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 :) )

@arnaudgiuliani
Copy link
Member

Does one of your parameters reference a ViewModel?

@trobertsca
Copy link
Author

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.

@arnaudgiuliani
Copy link
Member

@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 ;)

@arnaudgiuliani arnaudgiuliani added android type:issue status:accepted accepted to be developed and removed question Usage question status:checking currently in analysis - discussion or need more detailed specs labels Jun 20, 2018
@arnaudgiuliani
Copy link
Member

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

I can investigate...

@arnaudgiuliani arnaudgiuliani added this to the 1.0.0 milestone Jun 20, 2018
@arnaudgiuliani
Copy link
Member

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

@trobertsca
Copy link
Author

Awesome! You rock :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants