📝If objects are immutable, older memory can never point to the newly-allocated memory

When all objects in an area are known to be immutable (e.g., Haskell), the older memory can never point to the newly-allocated memory.

This can speed up garbage collection: A generational GC can skip scanning an old generation if it is known to not contain references to newer generations, and with immutable data—they never are.

Of course, if the language has a mutable memory, it still needs to be scavenged to find possible references. Although, optimizations are available.

Backlinks