title: Memory Leak due to Snackbar
body: <p>I´ve just added CanaryLeak to my project to see if there are any memory leaks in my application and noticed, that there is indeed a leak in one my fragments due to a Snackbar.</p>
  
  <p>I´m creating a Snackbar in the <code>onCreateView</code> and set it to <code>null</code> in <code>onDestroyView</code>. However I get a memory leak every time I rotate the screen.</p>
  
  <pre><code>
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup 
      container, Bundle savedInstanceState) {
  
          View view = inflater.inflate(R.layout.fragment_backend, container, 
          false);
  
          Activity parentActivity = getActivity();
          if (parentActivity != null) {
              mConnectSnackbar = 
              Snackbar.make(parentActivity.findViewById(R.id.nav_host_fragment), 
              "Connect", Snackbar.LENGTH_INDEFINITE);
  
              mConnectSnackbar.setAction(getString(R.string.connect), v -&gt; 
              startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)));
          }
  
          return view;
      }
  
      @Override
      public void onDestroyView() {
          super.onDestroyView();
          mConnectSnackbar.setAction("Connect", null);
          mConnectSnackbar.dismiss();
          mConnectSnackbar = null;
      }
  
  </code></pre>
  
  <p>As I clear the reference to the action and the Snackbar itself there shouldn´t be any reason for a memory leak. However I can´t figure out, what the reason might be and the Heap Dump from Canary Leak doesn´t help either.
  I have a suspicion that it might me due to the reference to the nav_host_fragment, but I don´t know if it´s true and how to fix it.</p>
  
  <p>Many Thanks for your help.</p>
  
  <h2>Edit 1:</h2>
  
  <p>Added Leak Trace and removed hprof file.</p>
  
  <pre><code>┬
  ├─ android.view.accessibility.AccessibilityManager
  │    Leaking: NO (a class is never leaking)
  │    GC Root: System class
  │    ↓ static AccessibilityManager.sInstance
  │                                  ~~~~~~~~~
  ├─ android.view.accessibility.AccessibilityManager
  │    Leaking: UNKNOWN
  │    ↓ AccessibilityManager.mTouchExplorationStateChangeListeners
  │                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ├─ android.util.ArrayMap
  │    Leaking: UNKNOWN
  │    ↓ ArrayMap.mArray
  │               ~~~~~~
  ├─ java.lang.Object[]
  │    Leaking: UNKNOWN
  │    ↓ array Object[].[4]
  │                     ~~~
  ├─ androidx.core.view.accessibility.AccessibilityManagerCompat$TouchExplorationStateChangeListenerWrapper
  │    Leaking: UNKNOWN
  │    ↓ AccessibilityManagerCompat$TouchExplorationStateChangeListenerWrapper.mListener
  │                                                                            ~~~~~~~~~
  ├─ com.google.android.material.snackbar.BaseTransientBottomBar$SnackbarBaseLayout$1
  │    Leaking: UNKNOWN
  │    ↓ BaseTransientBottomBar$SnackbarBaseLayout$1.this$0
  │                                                  ~~~~~~
  ╰→ com.google.android.material.snackbar.Snackbar$SnackbarLayout
  ​     Leaking: YES (View.mContext references a destroyed activity)
  ​     mContext instance of android.view.ContextThemeWrapper, wrapping activity com.twaice.twaice.MainActivity with mDestroyed = true
  ​     View#mParent is null
  ​     View#mAttachInfo is null (view detached)
  ​     View.mWindowAttachCount = 0
  </code></pre>