Garbage collection

If I am not mistaken, activity objects are never destroyed from memory; they always exist until the process is killed. Thus, calling the finish () function or the Android operating system that destroys your activity does not mean that it is destroyed in memory, but only means now in a "destroyed state" (unofficial name).

To demonstrate, I redefined the method for completing my activity, and then used System.gc () from the button event of another action. I see that the method of completing my activity is being called. If activity objects cannot be destroyed at runtime, how can data be collected from garbage?

+4
source share
2 answers

If there is no more activity link, then it gets garbage collection - but the activity leak is very simple - this suggests that now there is a really good tool for finding activity leaks: https://github.com/square/leakcanary Also activity is only GCed after onDestroy () was called - not immediately after the finish () - therefore, your measurement does not work

+5
source

Each Activityprocess is stored in memory until space is required, or the user forcibly removes it from the process manager, for example, the retentate list (while holding the home / middle button).

MRU. , finish() / onDestroy, , finish() / onDestroy, , JVM , , , , . - .

0

Source: https://habr.com/ru/post/1611323/


All Articles