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

[proposal] linking the view pool to activities to lifecycle owner #1099

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eboudrant
Copy link
Contributor

This is a proposal and will require an update to Hilt, see google/dagger#2202 (comment).

The idea of theses changes in to Epoxy and Hilt are to fix a memory leak. It happen because Epoxy link the view pool to the activity. However, when a view get inflated in a Hilt fragment, the view's context is a wrapper and hold a reference on the fragment. The fragment leak for the whole activity lifecycle.

So why Epoxy link the view pool arbitrary to the Activity? Instead, could we use the view's context and find the closest LifecycleOwner. When this lifecycle get destroyed we can clear the pool.

It is a proposal, happy to discuss here. Using the LifecycleOwner instead of Activity looks natural. Is it possible to use Epoxy outside of an Activity that is not a LifecycleOwner?

…ink to a lifecycle owner?

The problem is with Hilt, there is a memory leak. The memory leak is because Epoxy link the view pool to the activity however, when a view get inflated in a Hilt fragment, the context is a wrapper and hold a reference on the fragment. The fragment leak.

So why Epoxy link the view pool arbitrary to the `Activity`. Instead, could we use the view's context and find the closest `LifecycleOwner`. Use the `LifecycleOwner`'s lifecycle ti decide when to clear the pool.

However this change won't be enough to fix the memory leak we have with Hilt. We will also need this change in Hilt :
Copy link
Contributor

@elihart elihart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes a lot of sense, and is cleaner anyway. I can't think of any cases it wouldn't work in, although I also don't know when the context wouldn't be an Activity (possible a Compose context? but epoxy wouldn't really be used there anyway, unless we have some interop)

}

if (isFinishing) {
if (lifecycle.currentState >= Lifecycle.State.DESTROYED) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can return directly here

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

Successfully merging this pull request may close these issues.

2 participants