title: Trying to detect ActionMode memory leak
body: <p>I have been trying to find the source of ActionMode memory leak for days now without luck. I have an activity with several fragments and when I leave the fragment having ActionMode (while auto cancelling it), LeakCanary detects a memory leak.</p>
  
  <p>I have nulled both ActionMode and ActionMode.Callback on destroy() and even tried doing it on onDestroyActionMode().</p>
  
  <p>Here is my LeakCanary screenshot:</p>
  
  <p><a href="https://i.imgur.com/RUbdqj3.png" rel="noreferrer">https://i.imgur.com/RUbdqj3.png</a></p>
  
  <p>I hope someone points me in the right direction.</p>
  
  <p>P.S. I have suspected it has something to do with ActionMode.Callback. Though, I could not find any methods for the CallBack that destroys it. I start the ActionMode using startSupportActionMode(mActionModeCallback). I have tried to find a method to remove the mActionModeCallback from that, too, but no methods.</p>
  
  <p>Here is my full ActionMode code:</p>
  
  <pre><code>private ActionMode mActionMode;
  private ActionMode.Callback mActionModeCallback;
  
  public void startCAB()
  {
      if (mActionMode == null)
          mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(mActionModeCallback);
  }
  
  
  private void buildActionModeCallBack()
  {
      mActionModeCallback = new ActionMode.Callback() {
          @Override
          public boolean onCreateActionMode(ActionMode mode, Menu menu) {
              MenuInflater inflater = mode.getMenuInflater();
              inflater.inflate(R.menu.menu_cab, menu);
              return true;
          }
  
          @Override
          public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
              return false;
          }
  
          @Override
          public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
              switch (item.getItemId()) {
                  ... Some Code ...
              }
          }
  
          @Override
          public void onDestroyActionMode(ActionMode mode) {
              mActionMode = null;
      mActionModeCallback = null; // Tried with and without this.
          }
      };
  }
  
  public void finishActionMode()
  {
      mActionMode.finish();
  }
  
  @Override
  public void onDestroy()
  {
      super.onDestroy();
      mActionMode = null;
      mActionModeCallback = null;
  }
  </code></pre>
  
  <p>Parent Activity containing fragments:</p>
  
  <pre><code>@Override
  public void onTabUnselected(TabLayout.Tab tab)
  {
      clearCAB();
  }
  
  private void clearCAB()
  {
      int index = mPagerAdapter.getCurrentFragmentIndex();
      FragmentOne fragmentOne = (FragmentOne) mPagerAdapter.instantiateItem(mViewPager, index);
      fragmentOne.finishActionMode();
  }
  </code></pre>