Managing and understanding memory
In Chapter 4, Structuring Code with Java Methods we learned a bit about references. Here is a quick recap
Note
… known as a reference type. They quite simply refer to a place in memory where storage of the variable begins but the reference type itself does not define a specific amount of memory used. The reason for this is straightforward.
We don't always know how much data will be needed to be stored in it until the program is executed.
We can think of Strings and other reference types as continually expanding and contracting storage boxes. So, won't one of these String reference types bump into another variable eventually?
As we are thinking about the device's memory as a huge warehouse full of racks of labeled storage boxes, then you can think of the DVM as a super-efficient forklift truck driver that puts the distinct types of storage boxes in the most appropriate places.
And if it becomes necessary, the DVM will quickly move stuff...