Total members 11890 |It is currently Thu Apr 25, 2024 9:02 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Eligible Objects For Garbage Collectors:
An example for you to understand when an object becomes eligible for garbage collectors. The following code snippet show you the number of object that is ready for java garbage collector .You need to keep in mind that JVM is the only controller when GC runs . Object become eligible when no of program thread can reach it (No reference to it).

Code:
public class JavaGC {

    public   static void main(String args[])
    {
        TestGC obj1 = new TestGC();
        TestGC obj2 = new TestGC();
        TestGC obj3 = obj1.dumpIt(obj2);
        obj1 = null;
        // What are the eligible objects here for GC . 
// Am here .
        
    
}
}

class TestGC 
{
    Long id;
    TestGC dumpIt(TestGC testGC)
    {
        testGC = null ; 
        return testGC 
;
    }
}
 


A t the line [b]“// Am here “ there are two object ready for GC . [/b]
1. The object of obj1.
2. The wrapper object inside the obj1 which is Long .

You can define a finalize() function for the class TestGC , this function is called once for every eligible instance before GC delete it .



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Eligible objects for garbage collectors
 Using Web Objects in XML (WOX) to serialize Java objects XML     -  
 What Is Garbage Collection?     -  
 garbage collection work in java     -  
 Can an object be garbage collected and it is still reachable     -  
 Get all objects for an entity     -  
 Smart Objects in photoshop     -  
 what is object's lock and which objects have locks ?     -  
 queue of objects keep track of the front and rear     -  
 invalid argument on IE with script to center objects     -  



Topic Tags

Java Basics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com