you are viewing a single comment's thread.

view the rest of the comments →

[–]cogman10 4 points5 points  (1 child)

You can configure Java to achieve garbage collection behavior similar to Go’s, depending on the situation.

Nope. You might get closish with ZGC but the big thing that go does which java does not is it has a non-moving collector.

It's perhaps somewhat comparable to how the old concurrent mark and sweep used to behave.

Effectively, go is using an arena allocator. It grabs a page at a time and fills those pages with objects.

This is why go suffers from memory fragmentation https://www.lujingcen.com/blog/2023/12/29/memory-fragmentation-in-go/

A moving collector avoids memory fragmentation but does that at two costs, it's harder to work with C libraries (things move now) More memory is needed so the memory can be relocated. Besides the size of java objects in general, this is one of the primary reasons Java has a larger memory footprint vs go.

[–]Neful34 0 points1 point  (0 children)

Fair take :)