Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions How Garbage Collector Works
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Mohammed Azeem Khan
How Garbage Collector Works
1 Answer(s)      7 years ago
Posted in : Java Interview Questions


how does Garbage Collection works?


Advertisement
View Answers

February 27, 2008 at 4:23 PM


Garbage Collection in Java

Garbage Collector
Garbage collection" means objects that are no longer required by the program are "garbage" and can be thrown away.
JVM?s heap stores all objects that are created by a running Java application. GC is the process that automatically freeing objects that are no longer referenced by the java program. JVM specification does not require any particular garbage collection technique. It doesn't even require garbage collection at all. More accurate and up-to-date definition of GC is "memory recycling."
When an object is no longer required by the program, the JVM heap space it occupies can be recycled ,so that the new space is made available for newly created objects. GC somehow determine which objects are no longer referenced by the program and make available the heap space occupied by such unreferenced objects. The process of freeing unreferenced objects, the GC must run any finalizers of objects for freeing objects. Heap fragmentation occurs through normal program execution. In heap fragmentation new objects are allocated, and unreferenced objects are freed so that free portions of heap memory can be used for occupying by live objects.
Requests for memory allocation by new objects is filled by extending the size of the heap even though there is enough total unused space in the existing heap. GC frees us from the burden of freeing allocated memory. GC know when to explicitly free allocated memory can be made available for new objects.


GC has the following advantages such as :-

(1) GC makes us more productive.Programming in non-garbage-collected languages face an elusive memory problem. Programming in Java using GC can avoid the problem of memory & scheduling .
(2) GC helps ensure program integrity. GC is an important part of Java's security strategy.


GC has the following disadvantages such as :-

(1) Garbage-collected heap is that ,contains an overhead that can affect program performance.
(2) Garbage-collected environment have less control over the scheduling of CPU time devoted to freeing objects that are no longer needed.
(3) JVM has to keep track, which objects are being referenced by the executing program, and finalize and free unreferenced objects on the fly.

if you want more details about Garbage Collector with example go to following URL :

GC in Java Tutorial resources
http://www.roseindia.net/java/beginners/GarbageCollection.shtml


Neetu ;)


Related Tutorials/Questions & Answers:
Garbage Collector
Garbage Collector  Hi, Can any one please tell me what are the types of garbage collector ?? Regards: Akash
Garbage Collection
; In the example we are describing how the garbage collector works... are creating three objects to give the garbage collector something to do, then we... in milliseconds into a long type variable then calling the garbage collector method
Advertisements
GARBAGE COLLECTOR
GARBAGE COLLECTOR  What is garbage collector in java?   In order to achieve run-time polymorphism in java following supports needed. At first overrides the super-class one or more methods in subclass this is due
garbage collector
garbage collector  Hi what is the adventage using system.gc() method ? what is the adventage f annotation in java ? how can we loads the spring...;Advantage of system.gc(): System.gc() runs the Garbage Collector.The JVM
Java garbage collector
Java garbage collector  What is the priority of Garbage collector thread
Java Garbage collector
Java Garbage collector  What kind of thread is the Garbage collector thread?  Hi Friend, It is a daemon thread. Thanks
Java garbage collector
Java garbage collector  Does garbage collection guarantee that a program will not run out of memory?  Hi, The Java Garbage Collector does not guarantee of this. Thanks
Java garbage collector
Java garbage collector  How you can force the garbage collection
garbage collector - Java Interview Questions
How Garbage Collector Works   how does Garbage Collection works?  Garbage Collection in JavaGarbage Collector Garbage collection"... unreferenced objects on the fly. if you want more details about Garbage Collector
Garbage collector thread - Java Beginners
Garbage collector thread  Hi, Please let me know what kind of thread is the Garbage collector thread? Thanks  Hi Friend, It is a daemon thread. Thanks
Java garbage collector
Java garbage collector  Which is garbage collected first: Normal variables or static variables
garbage collector - Java Interview Questions
garbage collector  what is the use of garbage collector?  Hi friend, import java.util.Vector; public class GarbageDemo{ public...; for (int i = 0; i < size; i++) { } System.out.println("Garbage
Garbage Collector - Java Interview Questions
Garbage Collector  Why Database Connection object is not Garbage Collected? As we need to close the connetion manually, not like with other objects garbage collected
Code for Garbage Collection
to force a garbage collector to work by creating many objects. Description... collection. First of all we have created an object for the garbage collector...(); method to show the time take by the garbage collector
Java garbage collection
Java garbage collection  How many times may an object's finalize() method be invoked by the garbage collector
How TCP/IP works ?
How TCP/IP works ?  hello,, Can some body tell me how TCP/IP works?   hii, TCP/IP is just a protocol that allows different nodes on the network/Internet to share resources and without TRANSMISSION CONTROL PROTOCOL
What is garbage collection? - Java Beginners
. How garbage collection works in java? Thanks   Garbage.... The Garbage collector is responsible for running the Garbage collection process.... But Garbage collector will finally decide weather to call Garbage collection
Garbage collection
Garbage collection  why garbage collection? How it works?   Garbage collection is one of the most important features of Java. The purpose of garbage collection is to identify and discard objects that are no longer
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
garbage collection in java
will learn how to force a garbage collector to work by creating many objects.... First of all we have created an object for the garbage collector to perform...(); method to show the time take by the garbage collector. import
garbage collection
garbage collection  how to use garbage collection in program using core java
How does getcurrentsession() method works in hibernate sessionfactory?
How does getcurrentsession() method works in hibernate sessionfactory?  Hi, Please explain how does getcurrentsession() method works in hibernate sessionfactory? Thanks...   Dear Friend, getCurrentSession() obtains
how to make this java mail works? - Java Beginners
how to make this java mail works?  Dear experts, Recently, I borrowed a book by William Broden and managed to get the source codes from the author... don't have a clue how to make this file work at all, even after reading
garbage collection - Java Beginners
then it will be automatically deleted by the garbage collector. It save the some amount..."algorithms.Instead of "destructor" in c++ , java supports garbage collector...garbage collection  wat is the use of garbage collection  
Java garbage collection
Java garbage collection  What is Garbage Collection and how to call it explicitly
Garbage collection process in java - Java Beginners
In Java the Garbage collection process is known as Garbage Collector. The Garbage.... Program can call the System.gc() method to call the Garbage Collector...Garbage collection process in java  Name the process used for Garbage
How Fleet management System works
If you have a fleet and you are wondering how fleet management system works or how can you can be benefited by managing your fleet, than there is no need to get anxious any more. Fleet management requires some skilled labor, software
c++ garbage collection implementation
c++ garbage collection implementation  How to implement the garbage collection program in C
How Struts 2 Framework works?
How Struts 2 Framework works? This tutorial explains you the working.... In this tutorial you will learn How Struts 2 works with the help of an easy... Language (OGNL) is used to reference and manipulate data on the ValueStack. How
How GPS Tracking System Works
Question arise in our mind "How does GPS Tracking system Works"? The Global Positioning system is a navigation system that is used to track objects like vehicles and mobiles. It is based on satellites, maps and computer software. People
Getting garbage value
Getting garbage value  Thanks for the reply. Its works well, but whenever I'm using numeric value from 0010 to 0757 it is returning some garbage value. I dont have the idea what is going wrong. Please give me some idea to solve
 

 

 

DMCA.com