title: Why it's recommended not to retain fragment with UI?
body: <p>I read that retaining fragment with ui and references on views can cause memory leaks. Than I create test app with fragment where I store some references on views and set setRetaineInstance(true), but several screen rotation does not cause any leaks. MAT says that I have only one instance of parent activity. What I'm doing wrong? In which cases retaining fragment with ui can cause leaks?</p>
  
  <p>RetainInstanceActivity.java</p>
  
  <pre><code>public class RetainInstanceActivity extends FragmentActivity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {        
      super.onCreate(savedInstanceState);
  
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(android.R.id.content, RetainFragment.newInstance())
                  .commit();
      }
  }}
  </code></pre>
  
  <p>RetainFragment.java</p>
  
  <pre><code>public class RetainFragment extends Fragment {
  
  private View mLogin;
  private View mPassword;
  private View ImageView;
  
  public static RetainFragment newInstance() {
      final RetainFragment fragment = new RetainFragment();
  
      return fragment;
  }
  
  @Override
  public void onCreate(final Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setRetainInstance(true);        
  }
  
  @Override
  public View onCreateView(final LayoutInflater inflater,
          final ViewGroup container, final Bundle savedInstanceState) {       
      final View view = inflater.inflate(R.layout.fragment_retain, container,
              false);
  
      mLogin = view.findViewById(R.id.login);
      mPassword = view.findViewById(R.id.password);
      ImageView = view.findViewById(R.id.img);
  
      return view;
  }
  </code></pre>
  
  <p>}</p>