I\'ve read that setting .setOnRetainInstance(true)
on fragments presenting UI may lead to memory leaks.
Could somebody please explain why and how this
setRetainInstance(true)
is used to retain instances of dynamic Fragments during an Activity recreation, such as a screen rotation or other config changes. This does not mean the Fragment will be retained forever by the system though.
When an Activity is terminated for other reasons, such as the user finishing the Activity (i.e. pressing back), the Fragment should be eligible for garbage collection.