I have a doubt about the memory implications of fragments. What will be the most optimum solution in terms of memory:
1) create one object for each fragment and use these objects in the transaction manager.
MyFragment myFrag=new MyFragment();
fragmentTransaction.replace(R.id.mainPager, myFrag);
2) create the fragment directly in the transaction manager and leave that the Garbage collector take account of this object, I mean something like this:
fragmentTransaction.replace(R.id.mainPager, new MyFragment());
Are there any difference between the two options in terms of possible memory leaks and performance optimisation.
Thanks!
This does not double the memory load. myFrag is just a reference to the new fragment, it only stores the memory location of the fragment, therefore the overload is negligible.