Garbage collection

Garbage collection

why garbage collection? How it works?

View Answers

July 13, 2012 at 10:37 AM

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 needed by a program so that their resources can be reclaimed and reused. Garbage collection is also called automatic memory management. In Java, it is good idea to explicitly assign null into a variable when no more in use. In Java on calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected. Garbage collection is an automatic process.


July 14, 2012 at 10:32 PM

many many thanks


July 18, 2012 at 12:55 AM

Few important points about garbage collection in java:

1) objects are created on heap in Java irrespective of there scope e.g. local or member variable. while its worth noting that class variables or static members are created in method area of Java memory space and both heap and method area is shared between different thread.
2) Garbage collection is a mechanism provided by Java Virtual Machine to reclaim heap space from objects which are eligible for Garbage collection.
3) Garbage collection relieves java programmer from memory management which is essential part of C++ programming and gives more time to focus on business logic.
4) Garbage Collection in Java is carried by a daemon thread called Garbage Collector.
5) Before removing an object from memory Garbage collection thread invokes finalize () method of that object and gives an opportunity to perform any sort of cleanup required.
6) You as Java programmer can not force Garbage collection in Java; it will only trigger if JVM thinks it needs a garbage collection based on Java heap size.
7) There are methods like System.gc () and Runtime.gc () which is used to send request of Garbage collection to JVM but itâ??s not guaranteed that garbage collection will happen.
8) If there is no memory space for creating new object in Heap Java Virtual Machine throws OutOfMemoryError or java.lang.OutOfMemoryError heap space
9) J2SE 5(Java 2 Standard Edition) adds a new feature called Ergonomics goal of ergonomics is to provide good performance from the JVM with minimum of command line tuning.









Related Tutorials/Questions & Answers:
garbage collection
garbage collection  how to use garbage collection in program using core java
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
Advertisements
Java garbage collection
Java garbage collection  What is Garbage Collection and how to call it explicitly
garbage collection in java
.style1 { color: #FFFFFF; } Garbage Collection in Java In java... through garbage collection. In other words it deallocate memory automatically which have no longer use. This technique is known as Garbage Collection
c++ garbage collection implementation
c++ garbage collection implementation  How to implement the garbage collection program in C
garbage collection - Java Beginners
object is subject to garbage collection when it becomes unreachable to the program...garbage collection  wat is the use of garbage collection  ... then it will be automatically deleted by the garbage collector. It save the some amount
garbage collection implementation dependent java
garbage collection implementation dependent java  How a garbage collection works in Java
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
Java garbage collection
Java garbage collection  How many times may an object's finalize() method be invoked by the garbage collector
Java garbage collection
Java garbage collection  Can an object be garbage collected while it is still reachable
What is garbage collection? - Java Beginners
What is garbage collection?   Hi, Tell me about garbage collection. How garbage collection works in java? Thanks   Garbage... Collection. The Garbage collection process is automatic and programmer can?t free
Java garbage collection
Java garbage collection  Can an unreachable object become reachable again
Java Garbage Collection
Java Garbage Collection      ... on garbage collection. The name "garbage collection" implies... but never freed explicitly by the code. Garbage collection is the process
Garbage collection process in java - Java Beginners
Garbage collection process in java  Name the process used for Garbage collection in Java? Thanks   Garbage collection process In Java the Garbage collection process is known as Garbage Collector. The Garbage
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
Garbage Collection
Garbage Collection      ... the garbage collection operation completes and subtracts the previous time from... GarbageCollection Staring explicit Garbage Collection. Garbage
Code for Garbage Collection
Code for Garbage Collection  ... collection. First of all we have created an object for the garbage collector... the garbage collection on that object. Then we have used the System.currentTimeMillis
Java garbage collector
Java garbage collector  How you can force the garbage collection
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
Collection
Collection  What is the exact difference between lagacy classes and collection classes? and Enumeration is possible on Collection classes
Garbage Collector
Garbage Collector  Hi, Can any one please tell me what are the types of garbage collector ?? Regards: Akash
collection
collection  As we know array holds the similar kind of elements, then in collection how toArray() method will convert the collection having different objects as elements to an array in java
collection
, Hashtable and Collections and Collection?   Enumeration : It is series... : It is re-sizable array implementation. Belongs to 'List' group in collection... Map in collection. Collections : It implements Polymorphic algorithms which
Collection
Collection  actually why do we need collections? means we can also store group of objects in relational data base and dbms also provides all the operatoins insert,delete,update,sort,search etc. then why collection
Java garbage collector
Java garbage collector  What is the priority of Garbage collector thread
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 - Java Interview Questions
garbage collector  what is the use of garbage collector?  ...; for (int i = 0; i < size; i++) { } System.out.println("Garbage Collection started explicitly."); long time = System.currentTimeMillis
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
Access Modifiers and Garbage Collection
Access Modifiers and Garbage Collection       Previously it was a requirement to allocate... step further in version 2.0 garbage collector is implemented as a conservative
Java garbage collector
Java garbage collector  Which is garbage collected first: Normal variables or static variables
ModuleNotFoundError: No module named 'garbage'
ModuleNotFoundError: No module named 'garbage'  Hi, My Python... 'garbage' How to remove the ModuleNotFoundError: No module named 'garbage... to install padas library. You can install garbage python with following command
WHAT IS GARBAGE COLLECTOR AND HOW IT IS USED
WHAT IS GARBAGE COLLECTOR AND HOW IT IS USED  WHAT IS GARBAGE COLLECTOR AND HOW IT IS USED   The garbage collector collects garbage. When you create object they produce garbage, and the garbage collector gets rid
garbage collector - Java Interview Questions
How Garbage Collector Works   how does Garbage Collection works?  Garbage Collection in JavaGarbage Collector Garbage collection"... any particular garbage collection technique. It doesn't even require garbage
Java Garbage collector
Java Garbage collector  What kind of thread is the Garbage collector thread?  Hi Friend, It is a daemon thread. Thanks
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
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
collection overview and collection interface
collection overview and collection interface  write the program for collection interface?   Please visit the following links: http://www.roseindia.net/java/jdk6/Collection-Interfaces.shtml http://www.roseindia.net
Collection Types
Collection Types  What are the Collection types in Hibernate
ModuleNotFoundError: No module named 'garbage-translator'
ModuleNotFoundError: No module named 'garbage-translator'  Hi, My... named 'garbage-translator' How to remove the ModuleNotFoundError: No module named 'garbage-translator' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'garbage-translator'
ModuleNotFoundError: No module named 'garbage-translator'  Hi, My... named 'garbage-translator' How to remove the ModuleNotFoundError: No module named 'garbage-translator' error? Thanks   Hi, In your
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
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
Collection framework
Collection framework  what are the real life examples of using Collection in java
Java Collection
Java Collection  What is the Collection interface
Jaca Collection
Jaca Collection  does Java collection allow incompatible types to be stored in single collection
Collection in java
Collection in java  What are the meaning of the letters E,T,K and V that come in the collection concept
collection and framework.
collection and framework.  please give some study material of collection and framework
Collection Api
Collection Api  which scenario we are using arraylist and linkedlist and vector
collection interface
collection interface  methods of collection interface and their description with example program?   Please visit the following links: http://www.roseindia.net/java/jdk6/Collection-Interfaces.shtml http

Ads