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

Memory leak with sharedViewModel and parameter #220

Closed
rubengees opened this issue Sep 9, 2018 · 6 comments
Closed

Memory leak with sharedViewModel and parameter #220

rubengees opened this issue Sep 9, 2018 · 6 comments
Labels

Comments

@rubengees
Copy link

Koin version: 1.0.0-RC-2

I experience a memory leak reported by LeakCanary when using sharedViewModel with a parameter.

I have a ViewModel like this:

class MainViewModel(private val someParameter: String) : ViewModel() {

    fun hello() {
    }
}

and inject it like this in my Fragment:

private val parameter = "hello"
private val viewModel by sharedViewModel<MainViewModel> { parametersOf(parameter) }

My module description is this:

val mainModules = module {
    viewModel { (someParameter: String) -> MainViewModel(someParameter) }
}

LeakCanary shows me this leak (hprof):

screenshot_20180909-124035

Here is a minimal Android project for reproduction. Just install the debug variant, open and close the app; the leak will show up.

If you need anything else, please ask.
Thanks for this great library and looking into this!

@arnaudgiuliani arnaudgiuliani added status:checking currently in analysis - discussion or need more detailed specs android type:issue version:1.0.0 and removed version:1.0.0 labels Sep 10, 2018
@arnaudgiuliani
Copy link
Member

Hello,

just ran your code but didn't trigger any memory leak :/ (Pixel 2, Nexus 5X)
had a background crash on setContent from Activity.

@arnaudgiuliani
Copy link
Member

(used API 25 & 27)

@rubengees
Copy link
Author

Hmm, I just tried it again with an API 25 emulator.
I checked out the repository, ran ./gradlew runDebug and closed the app.
The leak(s) did show up...

@arnaudgiuliani
Copy link
Member

Got it.

@arnaudgiuliani arnaudgiuliani added status:accepted accepted to be developed and removed status:checking currently in analysis - discussion or need more detailed specs labels Sep 10, 2018
arnaudgiuliani pushed a commit that referenced this issue Sep 10, 2018
@arnaudgiuliani
Copy link
Member

Try with RC-3

@rubengees
Copy link
Author

Works perfectly, thanks!

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