injected with Dagger in lots of ViewModels to perform network requests that are to be done no matter what happens to the lifecycle of the ViewModel.
I am purposely trying to prove that this is a really bad practice, so with the help of LeakCanary I am running code that looks like this:
My understanding is that you would only get something to leak if you have permanent references to UI or ViewModel long after they have been cleaned up
g
galex
10/26/2023, 7:03 AM
Thanks! I think we do catch a leak but I don't manage to reproduce it
g
gildor
11/14/2023, 7:01 AM
It will leak only if doSomeNetworkRequest touches Activity/Views. if not, there is no reason for Lambda to keep reference to Activity/Context, so it will not cause leak automatically, Kotlin compiles lambda differently, depending on case