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



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

Have Programming Question? Ask it here!
 
 
 


Mohammed Azeem Khan
How Garbage Collector Works
1 Answer(s)      6 years and 7 months 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
c++ garbage collection implementation
c++ garbage collection implementation  How to implement the garbage collection program in C
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
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
php garbage collection sessions - PHP
php garbage collection sessions  i wanted to know more about the php garbage collection sessions.. how can i create and hold
How Voice over Internet Protocol (VoIP) Works
. It is still a mystery for them the how do voice over IP (VoIP) works. But using VoIP servies is very easy once you know how it works. How VoIP Works? Voice... change your idea of making telephone calls. How does VoIP or voice over internet
Java Garbage Collection
. The garbage collector determines which objects are no longer referenced... Java Garbage Collection      ... on garbage collection. The name "garbage collection" implies
Java garbage collection
Java garbage collection  Can an object be garbage collected while it is still reachable
Java garbage collection
Java garbage collection  Can an unreachable object become reachable again
VoIP Works
VoIP Works How VoIP Works If you've never heard of VoIP...;   How VoIP Works-Busting Out of Long Distance Rates... over Internet Protocol, and how VoIP works is actually quite revolutionary because
Getting garbage value
Getting garbage value  Thank You Sir for helping me out from the problem. Now I'm facing some problem with the value I'm passing to the textfield from the link gets some garbage value whenever I'm using some particular set
Getting garbage value
Getting garbage value  Thank You Sir for helping me out from the problem. Now I'm facing some problem with the value I'm passing to the textfield from the link gets some garbage value whenever I'm using some particular set
How Ajax Works
How Ajax Works         How Ajax Works Ajax adds an extra layer of functionality in the communication model. Ajax engine acts
What is the purpose of garbage collection in Java, and when is it used?
What is the purpose of garbage collection in Java, and when is it used?  Hi, What is the purpose of garbage collection in Java, and when is it used... of Garbage collection in Java. so Please visit the link and clear your doubts
Works only for one row
Works only for one row   Hi, My below code is working only if there is a single row. could you please help me in doing it for all the rows retrieved from the database. <%@page import="java.util.concurrent.CountDownLatch
How Web Hosting works?
How Web Hosting works?   ... the working of Web Hosting service. We will explain you How Web Hosting works? Web... and running. How Web Hosting works? When user types website address
How jQuery works?
How jQuery Works?      This section we will see how jQuery works with the help of simple program... from the server. So, jQuey is very useful tool. Let's see how it works
How does Email works
How does Email works       Each Internet domain has email Server, when a user sends an Email… Email client Program sends the message to Email server. Email
How GPS Works?
How GPS Works?       Introduction GPS or Global Positioning System is a technology for locating.... The Idea behind GPS The GPS system works with the help of a satellite network
How Struts Works
How Struts Works       The basic purpose of the Java Servlets in struts is to handle requests made by the client or by web browsers. In struts JavaServerPages (JSP) are used
GPS Tracking: How it works
you can know the speed of an object, the distance traveled and how long it has
Works when run from desktop but....
Works when run from desktop but....  I used the code provided here for a pie chart using swing in Java, and when I saved it to my desktop, it ran fine, and worked as explained, but then I tried to add the same code to NetBeans
java - Java Beginners
java  how tha garbage collector know that the object will be deleted? on which algorithm the garbage collector works? what is the working principle of garbage collector? How manay types of garbage collectors r
Advertisements
 

 

 

DMCA.com