I found this code in old legacy system and I don't want to touch it, if there is nothing wrong with it.
But I feel like this code has some flaw and I can't locate it. Is this just not common pattern or there is some hidden pitfalls or memory leaks?
private static final Foo action = new Foo() {
@Override
public void onAction(MyDialogFragment fragment) {
if (fragment.getContext() != null) {
fragment.getActivity().finish();
}
}
};
This code is used in a fragment
UPDATE: I suspect that an object of anonymous inner class has a reference to a parent fragment and since an object of this class saved in static field, it will never be collected, so parent fragment will never be collected too. Are my reasonings wrong?