Skip to main content

Garbage Collection

Compaction

To fix fragmentation, the garbage collector compacts the heap. It moves objects together and updates their references. This creates larger free blocks of memory. It also makes memory faster to hand out and cuts fragmentation.

Compaction is transparent

Compaction changes where objects live in memory. But this is hidden from the app. The app doesn't need to know the new memory addresses.

This is exactly why the JVM never gives out the address.