*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbase Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbase Collection" Watch "Garbase Collection" New topic
Author

Garbase Collection

Purujit Saha
Ranch Hand

Joined: Nov 01, 2005
Posts: 86
class A
{
static String astr=new String("ABC");

int i=10;

public void sum()
{
System.out.println("SUM = "+i);
}
}

public class Test
{
public static void main(String arg[])
{
A a=new A(); // line 1
Object b=new Object(); // line 2
A c=new A(); //line 3

b=c; // Line 4
a=c; // Line 5
}
}

How many Objects will be eligible for Garbase Collection at line 4 & 5
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

This is defintely not advanced Java; this really doesn't even belong in the Java in General forums at all. I'm moving it to SCJP.


[Jess in Action][AskingGoodQuestions]
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
In the main method after executing Line 5 two objects will be eligible for GC.


Thanks & regards, Srini
MCP, SCJP-1.4, NCFM (Financial Markets), Oracle 9i - SQL ( 1Z0-007 ), ITIL Certified
Purujit Saha
Ranch Hand

Joined: Nov 01, 2005
Posts: 86
Whats about the static class variables & instance variables...
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Can variables be eligible for Gc..?
Srinivasa Raghavan
Ranch Hand

Joined: Sep 28, 2004
Posts: 1228
Instances of class ( the objects ) are eligible for GC.
[ November 11, 2005: Message edited by: Srinivasa Raghavan ]
Lakshmanan Arunachalam
Ranch Hand

Joined: Nov 02, 2005
Posts: 99
Objects created in line 1 and 2 will be eligible for GC.


Regards<br />Lakshmanan<br />IBM-OOAD & UML, SCEA-I
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Originally posted by A Kumar:
Can variables be eligible for Gc..?


Tricky... kumar. GC applies only to objects as far as i know. correct me if I am wrong.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 979
Tricky... kumar. GC applies only to objects as far as i know. correct me if I am wrong



Yes you are right...

I wrote this ..

Originally posted by A Kumar:
Can variables be eligible for Gc..?


because Purujit had asked..


Whats about the static class variables & instance variables..


That was a question for him....so that he could get it right...

Only objects are GC'ed....

Regards
Mahendar Reddy
Ranch Hand

Joined: Sep 27, 2005
Posts: 73
Originally posted by Purujit Saha:
Whats about the static class variables & instance variables...


Hi Purujit Saha,
Static ref-vars remains till class is available.
Instance ref-vars becomes eligible when the object becomes eligible.




SCJP- 98%<br />SCWCD-92%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Garbase Collection