Garbage collection is a technique used for automatic memory management within an operating system. In programming environments that do not offer automatic memory management, a software developer must reserve memory space with the operating system by manual calls and also release it again after use. Only in this way can the memory be reused for other purposes. If the program logic for releasing the memory contains errors, memory leaks can occur.
With garbage collection, the reserved memory areas are automatically examined to determine whether they can be released again. The corresponding evaluation can take place according to various criteria. The release itself also takes place automatically.
Garbage collection simplifies programming and helps to avoid memory leaks, but cannot completely rule them out. In addition, the garbage collector places a greater load on the computer in many respects than a good manual memory release and can thus have a negative effect on the execution speed of a program.