I made a simple app to test the memory of Android.
It has two Activities, A and B.
A is a simple Activity with a button that starts B.
B consists of a pretty big image (jpg, 1024×768 pixel in mdpi)
When I monitor this process using DDMS, heap goes up as expected when moving from A to B.
When I press (hardware, or software using super.onBackPressed()) button on B and end up in A again, the heap does not shrink again, even after calling garbage collection. Is this expected? Will the memory taken up by B ever be released during the lifetime of the process?
Please note that the garbage collector works “nondeterministic“. In particular, even a call to the garbage collector does not mean that the memory is completely freed. It is only guaranteed that the memory is freed if more memory is requested.