I'm curious about how JavaScript handles memory fragmentation during garbage collection. Does it have automatic compaction features like C# does, or does it not address fragmentation at all? And could you still encounter a fatal out-of-memory error even if there is plenty of free space, just fragmented?
1 Answer
Modern JavaScript engines, such as V8, employ a mark-sweep-compact algorithm for their garbage collection. After the sweep phase, they compact the memory to help prevent fragmentation. You can check out more details in the write-up on the V8 blog if you're interested: v8.dev/blog/trash-talk.

Thanks, this is exactly the info I needed! Though, if I had a nickel for every time I looked for "the compactor moves" instead of "THE SCAVENGER EVACUATES," I’d be rich. It's funny how tough terminology can make finding info online!