title: How to destroy old fragments in FragmentStatePagerAdapter
body: <p>I want to implement this:
  <img src="https://i.stack.imgur.com/jKOsg.png" alt="enter image description here"><br>
  I use a ViewPager with a FragmentStatePagerAdapter.<br>
  I started with the example from this page:<br>
  <a href="http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html" rel="noreferrer">http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html</a></p>
  
  <p>This is my ViewPager adapter:  </p>
  
  <pre><code>    public static class MyAdapter extends FragmentStatePagerAdapter {
          public MyAdapter(FragmentManager fm) {
              super(fm);
          }
  
          @Override
          public int getCount() {
              return NUM_ITEMS;
          }
  
          @Override
          public Fragment getItem(int position) {
              return ArrayListFragment.newInstance(position);
          }
  
          @Override
          public void destroyItem(ViewGroup container, int position, Object object) {
              super.destroyItem(container, position, object);
          }
      }
  </code></pre>
  
  <p>Every page of my ViewPager contains a ListView with some data.
  At the moment when I switch to a new page in ViewPager it will increase the RAM memory very quickly.<br>
  How should I remove the old fragments ?<br>
  I also used this but it does nothing:  </p>
  
  <pre><code>public void destroyItem(ViewGroup container, int position, Object object) {
  
      FragmentManager manager = ((Fragment) object).getFragmentManager();
      FragmentTransaction trans = manager.beginTransaction();
      trans.remove((Fragment) object);
      trans.commit();
  
      super.destroyItem(container, position, object);
  }
  </code></pre>
  
  <p>There is also a 1-2 seconds delay after I switch quickly to a new page or old page. Is there any technique to remove that delay. If I switch to a new page and wait for 2 second then on next switch there is no more delay.</p>
  
  <p>Tested on Nexus 7.</p>