Blog: GC

James Lu jamtlu at gmail.com
Sun Mar 7 20:24:36 UTC 2021


On Saturday, 6 March 2021 at 03:07:32 UTC, Max Haughton wrote:
>
> I vaguely agree that the Garbage Collector as a global concept 
> is dated, however: Be realistic - every programming language 
> has guidelines (http://dev.stephendiehl.com/hask/ Even for 
> Haskell they can be enormous) and dos and don'ts.

Modern garbage collection is region-based memory management with 
only two regions: One region where you can allocate for objects 
that will soon die, and one region for old objects, that if you 
leave garbage in, your application will pause because every 
object allocated forces an eventual Sweep phase, forcing the 
runtime to look at every single object, making memory allocation 
an O(N*G) operation, where G is the amount of old space garbage, 
and N is the amount of total objects. That easily becomes O(N^2).

(Yes, I'm aware of ZGC and Shenandoah, but most GCs don't work 
that way.)


More information about the Digitalmars-d mailing list