title: Fragments Garbage collection
body: <p>I am using Fragments in my app and i have doubt that by adding and removing fragment every time, Is the fragment garbage collected when you remove it?</p>
  
  <p>Here is my code :</p>
  
  <p>in onCreate()</p>
  
  <pre><code> FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
   fragmentTransaction.add(detailFragmentID, new MyDetailFragment());
   fragmentTransaction.add(fragmentID, new MyListFragmentt());
   fragmentTransaction.commit(); 
  </code></pre>
  
  <p>in onRestart() </p>
  
  <pre><code> FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
   Fragment previousFragment = getSupportFragmentManager().findFragmentById(detailFragmentID);
   if (previousFragment != null) {
       fragmentTransaction.remove(previousFragment);
   }
   fragmentTransaction.add(detailFragmentID, new MyDetailFragment());
   fragmentTransaction.commitAllowingStateLoss();
  </code></pre>
  
  <p>Here when i go to some activity and come back onRestart will be called.</p>
  
  <p>by adding and removing fragment every time, Is the fragment garbage collected here?</p>
  
  <p>[Formatted the code properly]</p>