Hi,
What is garbage collection?
Hi,
What is garbage collection?
In computing, garbage collection (also known as GC) is a form of automatic memory management. The garbage collector or collector attempts to reclaim the memory used by objects that will never be accessed again by the application or mutator. Garbage collection was invented by John McCarthy around 1959 to solve the problems of manual memory management in his recently devised Lisp programming language.
Many computer languages require garbage collection, either as part of the language specification (e.g. Java, C#, Dylan) or effectively for practical implementation (e.g. formal languages like lambda calculus); these are said to be garbage-collected languages. Other languages were designed for use with manual memory management, but have garbage collected implementations (e.g., C, C++). In either case, it is far easier to implement garbage collection as part of the language's compiler and runtime system, but post hoc GC systems exist, including ones that do not require recompilation. The garbage collector will almost always be closely integrated with the memory allocator.
Garbage collection relieves programmers from the burden of freeing allocated memory. Knowing when to explicitly free allocated memory can be very tricky.
A second advantage of garbage collection is that it helps ensure program integrity. Garbage collection is an important part of Java's security strategy. Java programmers are unable to accidentally (or purposely) crash the JVM by incorrectly freeing memory.
When a Java object becomes unreachable to the program, then it is subjected to garbage collection. The main use of garbage collection is to identify and discard objects that are no longer needed by a program so that their resources
can be reclaimed and reused.When an object is no longer referred to by any
variable,java automatically reclaims memory used by that object.This is known as garbage collection.
System.gc() method may be used to call it explicitly.
Java runtime system performs the garbage collection asynchronously depending on the available resources. When there are no more references to an object, the object is finalized and when the Garbage Collections starts these finalized objects gets collected.
Sometimes you need to run garbage collector explicitly just before some memory intensive task. You can run garbage collector by this statement.
System.gc();
Finalization process can also be invoked explicitly using the following statement. After the execution of this statement all the objects those are without reference, are finalized.
System.runFinalization();
garbage collection is collecting the allocated memory which is not in use..
or
garbage collection is the process of collecting the memory which is no longer used..
Bookmarks