android - FragmentTransaction, Frame Container, Freeing Fragments and Memory Management -
i have frame layout use swapping fragments. use navigation drawer , every menu item opens fragment. sure in app cycle there only 1 fragment on screen @ same time (and 1 activity). below can find 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 checked on android studio, everytime replace fragment above method, memory usage increases. fragmenttransaction.remove
not free fragments , replace
not free too. after while if click every menu item , open fragments on again , again, memory usage increases lot.
so question how can free old-replaced fragments? want 1 in memory. or can say; want destroy them
until activity dies, references fragments exist in memory. regardless of add/remove operations happened @ fragment manager level / backstack.
have on this stack overflow answer martÃn marconcini.
a work around can hiding , showing frgaments if exists in stack. have on this.
Comments
Post a Comment