Somebody told me the following, but I am a bit perplexed.
Please, would you be able to confirm or dispute it?
(the Fragment is
From a practical point of View
: The main reason for memory leaks is keeping static
fields, in particular static Context
, which should be avoided. Within an attached Fragment
, this usually is not even required. static
fields should be called .close()
and set to null
before super.onDetach()
or super.onDestroy()
. One does not even have keep handles to any views, when using data-binding. In Kotlin there are also synthetic accessors for that. Keeping handles to views is not required at all, which renders the question obsolete. This was required before both of these existed. Use lint, ktlint or leakcanary or memory-profiler to find potential memory leaks.