Garbage refers to data, objects or other regions of the memory on a computer system or other system resources which will not be used in any future computation by the system or any program running on In other words, garbage is the information stored in a memory that has no significance and usually does not make sense that is not needed.
Garbage is formed by pressing the random keys on your keyboard is one example. Sometimes, while opening a file if it appears to be garbage, it's likely that the file is encrypted or formatted to be open in a specific program. For example, a .DOC file opened in Microsoft Word will look normal. However, opened in a plain-text editor will appear as a garbage.
Types of Garbage:
Garbage is generally classified into two types:
The syntactic garbage is a subset of semantic garbage since an object can hold a reference to another object without the latter object being used. Resolving of the semantic garbage in a program is generally undecidable; however there are many algorithms for identifying syntactic garbage.
What is Garbage collection?
As computer systems all have fixed amounts of memory, it is necessary to deallocate the garbage frequently and return it to the heap, or memory pool, so that the underlying memory can be reused. This process of the removing the garbage and freeing space for reuse is called “garbage collecting”.
Previously, programmers have had to write programs that explicitly requested storage and then returned it to the system when it was no longer needed. Now, the Garbage collection automatically analyzes the state of a program, identify garbage, and deallocate it without intervention by the programmer.