Garbage collection is a technique for keeping track of various elements of memory in order to avoid memory leaks while a program is running.
The garbage collector is a component that allocates and deallocates memory as needed by an application. This is accomplished by conducting checks on the application’s references to variables and objects. Memory is deallocated and freed up when an object is no longer required by the program.