Answer the question
In order to leave comments, you need to log in
How does the garbage collector work with objects?
I'm interested in the features of memory cleaning by the garbage collector, namely how it behaves with objects passed to functions.
Example #1.1 :
val ft = supportFragmentManager.beginTransaction()
var fragment = ListObjectsFragment()
ft.replace(R.id.fragment_container, fragment, LIST_OBJECTS_FRAGMENT)
ft.commit()
val ft = supportFragmentManager.beginTransaction()
var fragment: Fragment?
fragment = ListObjectsFragment()
ft.replace(R.id.fragment_container, fragment, LIST_OBJECTS_FRAGMENT)
ft.commit()
fragment = null
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.fragment_container, ListObjectsFragment(), LIST_OBJECTS_FRAGMENT)
ft.commit()
Answer the question
In order to leave comments, you need to log in
Reasoning is wrong. Read FragmentManager code. In none of the cases will the object be marked, deleted, etc. The link to it will remain in the transaction.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question