Garbage collection
How garbage collection frees memory automatically: reachability and roots, reference counting and its cycle problem, mark and sweep, compaction, generational collection, how Java, Python, JavaScript, Go and C# do it, pauses and tuning, and how memory leaks still happen in collected languages.
CodexBash, , 5 min read
Every object a program creates takes memory, and that memory must eventually be given back. In C you call free yourself, and forgetting causes leaks while freeing too early causes crashes. Most modern languages, Java, Python, JavaScript, C#, Go, instead use garbage collection (GC): the runtime finds objects the program can no longer use and reclaims their memory automatically. This article explains how collectors decide what is garbage, the main algorithms, how popular languages implement them, and why "automatic" does not mean "leak-proof".
Sign in to read the rest
The whole 5 minute article is free with an account, along with every problem, lesson and tutorial. No card.