Should I explicitely set all variables of fragment to null in onDestroy (or onDetach) method to avoid memory leaks? Or it is not necessary, and they will be GCed when fragment is "destroyed". What are the best practices? Thanks in advance!
Just add-on,
You don't need to worry about this. The GC will take care of it. In Java you pretty much have to TRY to have a memory leak (yes, it's possible, but very rare). So, don't worry about it. If you do set the variables to null
you would just end up wasting time on code you don't need, and would add to maintenance down the road. The GC in Java does a great job of destroy variables and objects that aren't referenced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With