Closed jemshit closed 8 years ago
Dagger knows nothing about Android and thus nothing about the Android activity lifecycle. Injected types are not automatically freed.
However, you interpreted that issue incorrectly. It is the presenter which is keeping a reference to the activity and preventing the activity from being garbage collected, not the other way around.
So we make each injectedVariable=null on onDestroy() or any other quick solution to prevent memory leak? I thought @ActivityScope etc.. on Components destroy all injected variables after that scope (Activity) is destoyed? On Fri, Feb 19, 2016, 16:59 Jake Wharton notifications@github.com wrote:
Dagger knows nothing about Android and thus nothing about the Android activity lifecycle. Injected types are not automatically freed.
However, you interpreted that issue incorrectly. It is the presenter which is keeping a reference to the activity and preventing the activity from being garbage collected, not the other way around.
— Reply to this email directly or view it on GitHub https://github.com/square/dagger/issues/519#issuecomment-186246542.
There is no leak. If the activity has outgoing references to dependencies and there are no incoming references to the activity it will be garbage collected.
Ok, so the problem was Presenter keeping ref to Activity. Thanks :+1:
One last question, after Activity is destroyed and so its Presenter is garbage collected, does Presenter still can hold references even it is garbage collected?
No. Once garbage collected an object doesn't hold any references.
On Fri, Feb 19, 2016 at 2:07 PM Jemshit Iskenderov notifications@github.com wrote:
One last question, after Activity is destroyed and so its Presenter is garbage collected, does Presenter still can hold references even it is garbage collected?
— Reply to this email directly or view it on GitHub https://github.com/square/dagger/issues/519#issuecomment-186363609.
I guess the thing i missed is Activity is destroyed
does not mean it is garbage collected.
Question: does Dagger remove reference to injected variables on
onDestroy()
of Activity ? Here a guy wrote Activity holds reference to injectedPresenter
variable after Activity is destroyed. Someone enlighten me, thanks.