title: Memory leak when I replace a Fragment
body: <p>I have just started to use LeakCanary and when I replace a Fragment, every time leaks increase. This is the LeakCanary report:</p>
  
  <pre><code>android.widget.LinearLayout instance
  ​     Leaking: YES (ObjectWatcher was watching this because com.home.app1.PostFragment received Fragment#onDestroyView() callback 
       (references to its views should be cleared to prevent leaks))
  </code></pre>
  
  <p>This is my Fragment Replace code:</p>
  
  <pre><code>public void change(Fragment fragment) {
  
      ((FragmentActivity) context).getSupportFragmentManager().beginTransaction()
  
              .replace(R.id.frameLayout, fragment, "fragment")
              .setTransitionStyle(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
              .addToBackStack(null)
              .commit();
  }
  </code></pre>
  
  <p>So I research on SO and some people say views must be clenead in <code>onDestroyView</code>. Then I tried this in <code>onDestroyView</code>: <code>fragmentView=null;</code> but nothing was changed. Also tried this:</p>
  
  <pre><code>if (view.getParent() != null) {
          ((ViewGroup) view.getParent()).removeView(view);
      }
  </code></pre>
  
  <p>But again nothing was changed. So I tried to make all views null like below:</p>
  
  <pre><code>   @Override
     public void onDestroyView() {
      super.onDestroyView();
      backButton=null;
      swipeLayout=null;
      imageView=null; ...etc.
     }
  </code></pre>
  
  <p>Eventually leaking warnings on LeakCanary disappeared. But I think this is not a solution and does not make sense because there may be many views. So what's the solution to avoid this leaks? Thanks.</p>