What is the purpose of garbage collection

The purpose of garbage collection is to identify and discard objects that are no longerneeded by a program so that their resources may be reclaimed and reused.

Showing Answers 1 - 9 of 9 Answers

The garbage collector collects the Java objects are unreachable to a program. It is also called as automatic memory management as it removes the unused variables or objects from the memory. It is an automatic process which cannot be forced.

  Was this answer useful?  Yes

garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in use object, or a referenced object, means that some part of your program still maintains a pointer to that object.

An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory used by an unreferenced object can be reclaimed. In a programming language like C, allocating and deallocating memory is a manual process. In Java, process of deallocating memory is handled automatically by the garbage collector

  Was this answer useful?  Yes

In simple terms we can say garbage collector removes the unreferenced objects from the memory.

In general the memory should have some limitation. In JVM for accomplishing tasks we create objects and make them to process and get the results but after accomplishing the tasks there is no need of those objects in memory. So we need some mechanism to remove those objects from memory that is none other than Garbage Collector.

What happens if we keep on creating objects in memory?
Ans :: Simple when threshold limit reaches in memory it throws OutOfMemoryError that abnormally terminates the currently running program. So this is not expected ryt ...... thats why using Garbage Collector we will remove unreferenced objects form JVM Memory.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions