This article introduces garbage collection, including an overview of garbage collection algorithms and how garbage collection is implemented in some popular programming languages including Java and Python. Before we get into that, let’s consider the pros and cons of garbage collection itself. Why is it such a common solution for memory allocation errors? We’ll start with the perils of memory management in languages like C and C++, which do not use garbage collection.
Memory allocation issues are only a subset of the problems common to C/C++ that cause potential bugs and vulnerabilities, but they are a large subset and are very annoying to track down and fix. Memory allocation bugs include the following scenarios: