Book Image

Node.js High Performance

By : Diogo Resende
Book Image

Node.js High Performance

By: Diogo Resende

Overview of this book

Table of Contents (14 chapters)

Chapter 3. Garbage Collection

When writing applications, managing the available memory is boring and difficult. When the application gets complex, it's easy to start leaking memory. Many programming languages have automatic memory management, helping the developer to forget about this management by means of a Garbage Collector (GC). The GC is only a part of this memory management, but it's the most important one and is responsible for reclaiming memory that is no longer in use (garbage), by periodically looking at disposed referenced objects and freeing the memory associated with them.

The most common technique used by GC is monitoring reference counting. This means that GC, for each object, holds the number (count) of other objects that reference it. When an object has no references to it, it can be collected, which means that it can be disposed and its memory freed.

In V8, the Node.js engine, this reference counting is not constantly checked. Instead, it's periodically scanned, and this...