3 ms·
From the FAQ: > I've heard that GC uses twice as much memory > This may be true of primitive collectors (like the two-space collector), but this is not genera
by cousin_it 12y ago
From the FAQ:
> I've heard that GC uses twice as much memory
> This may be true of primitive collectors (like the two-space collector), but this is not generally true of garbage collection. The data structures used for garbage collection need be no larger than those for manual memory management.
Is that true? What GCs use less than 2x memory and have good performance?
- hga 12y agoGenerational garbage collectors achieve good/better performance by more frequently sweeping one or more heaps with younger items before promoting the survivors to an older heap, based on the thesis is that most garbage is short lived. Modern marking collectors are evidently pretty fast and many collect mostly concurrently with running code, eventually the whole heap has to be collected and the "world stops". The standard (being replaced?) Hotspot collector, without any special hardware tricks, was said in the Pauseless GC paper to sweep 1 GiB/second on standard x86_64 hardware. As in, when it has to do a full collection and stops everything else it goes that slowly, or at least it can be way too slow for many users with 10s or 100s of GiB of memory. Pauseless and C4 use hardware tricks, C4 on standard hardware, like using large pages, and making mass VM operations in one (added to Linux) call, only invalidating the TLB at the end. Oh, yeah, however efficient/inefficient they are, they collect concurrently with running code.
- bjourne 12y agoAll of them. :) A common setup for a generational garbage collector is to have the nursery use a copying collector, which indeed peaks at twice the memory usage, and then have a tenured generation use a mark and sweep collector. But, roughly, the tenured generation is often 1000 mb or more in size and the nursery only 1 mb. And 1000 + 2*1 isn't that much more than 1000 + 1. (The above is a huge oversimplification, there are thousands more gc setups that offer different tradeoffs between time and space)