I have a frame layout which i use for swapping fragments. I use navigation drawer and every menu item opens a fragment. So it is sure that in the all app cycle there will be only 1 fragment on screen at the same time (and thus 1 activity). Below you can find my fragment start method
public void startFragment(Fragment f)
{
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
transaction.replace(R.id.fragment_container, f);
transaction.commit();
}
So when i checked on Android Studio, everytime i replace fragment with above method, memory usage increases. FragmentTransaction.remove
does not free fragments and replace
also does not free too. So after a while if i click every menu item and open fragments over again and again, memory usage increases a lot.
So my question is how can i free old-replaced fragments? I want only one in memory. Or we can say; I want to destroy them