Garbage means trash or waste. The term garbage is generally used for data that is no longer needed after a program run and can be destroyed.
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 checked to see whether they can be released again. The corresponding evaluation can take place according to various criteria, and the release itself also takes place automatically.
Garbage collection simplifies programming and helps to avoid memory leaks, but cannot completely exclude them. In addition, the garbage collector places a greater load on the computer in many respects than a good manual memory release and can thus negatively influence the execution speed of a program.