• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Garbase Collection

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whats about the static class variables & instance variables...
 
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can variables be eligible for Gc..?
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instances of class ( the objects ) are eligible for GC.
[ November 11, 2005: Message edited by: Srinivasa Raghavan ]
 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Objects created in line 1 and 2 will be eligible for GC.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
reply
    Bookmark Topic Watch Topic
  • New Topic