• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbase Collection

 
Purujit Saha
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the main method after executing Line 5 two objects will be eligible for GC.
 
Purujit Saha
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats about the static class variables & instance variables...
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can variables be eligible for Gc..?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instances of class ( the objects ) are eligible for GC.
[ November 11, 2005: Message edited by: Srinivasa Raghavan ]
 
Lakshmanan Arunachalam
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects created in line 1 and 2 will be eligible for GC.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic