From 41c4e04da79b5edc6f4f2dff485f10896cb31849 Mon Sep 17 00:00:00 2001 From: Brad Corso Date: Fri, 9 Apr 2021 16:31:24 -0700 Subject: [PATCH] Fix leak in FragmentContextWrapper by releasing the baseInflator if it exists. Fixes https://github.com/google/dagger/issues/2070 RELNOTES=Fix leak in FragmentContextWrapper by releasing the baseInflator if it exists. PiperOrigin-RevId: 367725173 --- .../hilt/android/internal/managers/ViewComponentManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java/dagger/hilt/android/internal/managers/ViewComponentManager.java b/java/dagger/hilt/android/internal/managers/ViewComponentManager.java index 4ed79f7c203..78614950af2 100644 --- a/java/dagger/hilt/android/internal/managers/ViewComponentManager.java +++ b/java/dagger/hilt/android/internal/managers/ViewComponentManager.java @@ -168,7 +168,6 @@ private static Context unwrap(Context context, Class target) { * *

A wrapper class to expose the {@link Fragment} to the views they're inflating. */ - // This is only non-final for the account override public static final class FragmentContextWrapper extends ContextWrapper { private Fragment fragment; private LayoutInflater baseInflater; @@ -181,6 +180,8 @@ public void onStateChanged(LifecycleOwner source, Lifecycle.Event event) { // Prevent the fragment from leaking if the view outlives the fragment. // See https://github.com/google/dagger/issues/2070 FragmentContextWrapper.this.fragment = null; + FragmentContextWrapper.this.baseInflater = null; + FragmentContextWrapper.this.inflater = null; } } };