If said in the language of computer science, then garbage collection is a type of memory management. It automatically cleans up unused objects and pointers in memory, so that it allows resources to be used again.

Some programming languages ​​have built-in garbage collection, while others require custom functions to manage unused memory.

A very common method is garbage collection which is called reference counting. This strategy simply counts how many references there are in memory to store each object . If an object has zero references, then they are considered unnecessary (respectable) and they can be deleted to free up the space of memory.

With advanced reference counting, it detects objects that refer only to one another, indicating that those objects that are now unused are in the parent process.

Garbage collection can also be done at compile-time, when the source code of a program is compiled into an executable program.

In this process, compiler that determines Which resources memory of that anytime and access will not be a matter of a certain time. Again adds such instructions that automatically deallocate those resources from memory.

While this is a very effective way to remove unused objects, it has to be done conservatively to prevent the references from being deleted which may be needed later in a program.

Garbage collection is a very important part of software development because it prevents programs from using more RAM . While it helps programs to run more efficiently, it also protects them from dangerous bugs, such as memory leaks, which can also crash a program.

« Back to Wiki Index