Garbage Memory Collection (GC) Task

Jump to: navigation, search

A Garbage Memory Collection (GC) Task is an automated computer memory management task that reclaims garbage, or memory occupied by objects that are no longer in use by the program



  • (Wikipedia, 2020) ⇒ Retrieved:2020-8-23.
    • In computer science, garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program. Garbage collection was invented by American computer scientist John McCarthy around 1959 to simplify manual memory management in Lisp.

      Garbage collection relieves the programmer from performing manual memory management where the programmer specifies what objects to deallocate and return to the memory system and when to do so. Other similar techniques include stack allocation, region inference, memory ownership, and combinations of multiple techniques. Garbage collection may take a significant proportion of total processing time in a program and, as a result, can have significant influence on performance.

      Resources other than memory, such as network sockets, database handles, user interaction windows, file and device descriptors, are not typically handled by garbage collection. Methods used to manage such resources, particularly destructors, may suffice to manage memory as well, leaving no need for GC. Some GC systems allow such other resources to be associated with a region of memory that, when collected, causes the work of reclaiming these resources.


  • "Garbage Collection (C# vs Java)",
    • QUOTE: In C and C++, many objects require the programmer to allocate their resources once declared, before the objects can be safely used. Releasing these resources back to the free memory pool once the object has been used is also the responsibility of the programmer. If resources are not released, the code is said to leak memory, as more and more resources are consumed needlessly. On the other hand, if resources are released prematurely, loss of data, the corruption of other memory areas, and null pointer exceptions can occur.

      Both Java and C# prevent these dangers by independently managing the lifetime of all objects in use by an application.

      In Java, the JVM takes care of releasing unused memory by keeping track of the references to allocated resources. Whenever the JVM detects that a resource is no longer referenced by a valid reference, the resource is garbage-collected.

      In C#, garbage collection is handled by the common language runtime (CLR) with similar functionality to that of the JVM. The CLR garbage collector periodically checks the memory heap for any unreferenced objects, and releases the resources held by these objects.