Garbage Collection
Compaction
To fix fragmentation, the garbage collector compacts the heap memory by moving objects together and updating their references. This process helps to create larger contiguous blocks of free memory, improving allocation efficiency and reducing fragmentation.
Compaction is transparent
The compaction process where the address location of the objects is changed is transparent to the application. This means that the application doesn't need to be aware of the changes in memory addresses.
This is exactly why the address is never disclosed by JVM.