Total members 9951 | Gratitudes |It is currently Sat Feb 11, 2012 10:59 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Question
 Question subject: Eligible objects for garbage collectors
PostPosted: Mon Aug 24, 2009 5:11 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2103
Location: Earth
Has thanked: 39 time
Have thanks: 56 time

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 .

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  


 Similar topics
 Topic title   Forum   Author   Comments 
 invalid argument on IE with script to center objects  Scripting Language  thedarkone184  0
 Get all objects for an entity  JPA  msi_333  0
 Smart Objects in photoshop  Photoshop tutorials  msi_333  0
 Serializing Java objects to XML with WOXIntroduction  Java  Casper  0
 Can an object be garbage collected and it is still reachable  Java  AskBot  1

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 3 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team