package androidx.appcompat.app;

import android.app.Activity;
import android.content.Context;
import android.view.Window;

import java.util.Map;
import java.util.WeakHashMap;

public class SkinAppCompatDelegateImpl extends AppCompatDelegateImpl {
    private static Map<Activity, AppCompatDelegate> sDelegateMap = new WeakHashMap<>();

    public static AppCompatDelegate get(Activity activity, AppCompatCallback callback) {
        AppCompatDelegate delegate = sDelegateMap.get(activity);
        if (delegate == null) {
            delegate = new SkinAppCompatDelegateImpl(activity, activity.getWindow(), callback);
            sDelegateMap.put(activity, delegate);
        }
        return delegate;
    }

    private SkinAppCompatDelegateImpl(Context context, Window window, AppCompatCallback callback) {
        super(context, window, callback);
    }

    @Override
    public void installViewFactory() {
    }
}

@@ -116,16 +116,52 @@
 indow;%0A%0A
+import java.lang.ref.WeakReference;%0A
 import j
@@ -301,32 +301,46 @@
 c Map%3CActivity, 
+WeakReference%3C
 AppCompatDelegat
@@ -341,16 +341,17 @@
 elegate%3E
+%3E
  sDelega
@@ -477,16 +477,30 @@
         
+WeakReference%3C
 AppCompa
@@ -508,16 +508,17 @@
 Delegate
+%3E
  delegat
@@ -518,16 +518,19 @@
 delegate
+Ref
  = sDele
@@ -552,16 +552,103 @@
 ivity);%0A
+        AppCompatDelegate delegate = (delegateRef == null ? null : delegateRef.get());%0A
         
@@ -806,16 +806,36 @@
 tivity, 
+new WeakReference%3C%3E(
 delegate
@@ -835,16 +835,17 @@
 elegate)
+)
 ;%0A      

fix memory leak