title: Memory issues - fragments
body: <p>I recently refactored a application and replaced a ViewFlipper for a FrameLayout on which I swap between Fragments.</p>
  
  <p>Each time user request one of the views:</p>
  
  <pre><code>    public void showLibraryOf(long publisherId) {
          library = new DownloadLibraryFragment(id, viewFactory());
  
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          ft.replace(R.id.container, library);
          ft.commit();
  
          library.setAdapterObserver(this);
      }
  
      public void showMyLibraryOf(long publisherId) {
          myLibrary = new MyLibraryFragment(id, viewFactory());
  
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          ft.replace(R.id.container, myLibrary);
          ft.commit();
      }
  
      public void showHelp() {
          FragmentTransaction ft = getFragmentManager().beginTransaction();
          ft.replace(R.id.container, new HelpFragment());
          ft.commit();
      }
  </code></pre>
  
  <p>I create a new Fragment and replace the old one. Those being removed from screen get onDestroy called, but the memory consumed by the bitmaps I load on the screen does not get removed, so the application crashes after some swap between the fragments.</p>
  
  <p>I also tried to remove references at onDestroy</p>
  
  <pre><code>@Override
  public void onDestroyView() {
      destroy();
      super.onDestroyView();   
      adapter.clear();
      adapter.clearObservers();
      adapter.notifyDataSetChanged();
  
      view.setAdapter(new ArrayAdapter&lt;Journal&gt;(getActivity(), 0));
  
      adapter = null;
      view = null;
  }
  </code></pre>
  
  <p>But the memory keeps growing.</p>
  
  <p>Anyone knows any solution? maybe reuse fragments? effectively destroy it? I'm listening.</p>