Android back button frees up activity memory?

I made a simple Android memory test application. It has two operations: A and B. A is a simple action with a button that starts B. B consists of a fairly large image (jpg, 1024x768 pixels in mdpi)

When I control this process using DDMS, the heap rises as expected when moving from A to B. When I press (hardware or software using the button super.onBackPressed()) on B and turn on again in A, the heap does not shrink again, even after call garbage collection. Is this expected? Will freed memory B ever be released during the entire process life cycle?

+5
source share
2 answers

Please note that the garbage collector works "non-deterministic". In particular, even calling the garbage collector does not mean that the memory is completely freed. It is guaranteed that memory is freed if more memory is requested.

+1
source

onBackPressed () just enter your activity B from BackStack , then your activity is no longer displayed (onStop () is called), but this process was not killed until Os needed it.

+3
source

All Articles