Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

help on Garbage Collection analysis

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please i need help on analysing garbage collection question like this:

how many objects are eligible for garbage collection after executing //line 12

class A{
A a;
public A(A a){
this.a=a;
}
public static void main(String args[]){
A a1=null;
A a2=new A(new A(null));
A a3=new A(a2);
a1=a3;
a1.a=new A(null);
a2.a=null; //Line12
System.gc();
}
}
 
Ademola Okerinde
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ademola Okerinde wrote:please i need help on analysing garbage collection question like this:

please And this 2nd one

how many objects are eligible for gabage collection after executing c.aob = null;

class A{
A aob;
public static void main(String args[]){
A a=new A();
A b=new A();
A c=new A();
a.aob=b;
b.aob=a;
c.aob=a.aob;
A d=new A().aob=new A();
c=b;
c.aob=null;
System.gc();
}
}




-----------------------------------------------------------------------------------------------------
how many objects are eligible for garbage collection after executing //line 12

class A{
A a;
public A(A a){
this.a=a;
}
public static void main(String args[]){
A a1=null;
A a2=new A(new A(null));
A a3=new A(a2);
a1=a3;
a1.a=new A(null);
a2.a=null; //Line12
System.gc();
}
}

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A similar question was asked a few years ago.

Take a look at this https://coderanch.com/t/417810/java-programmer-SCJP/certification/Garbage-Collection
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please Search First
 
Ranch Hand
Posts: 64
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

please And this 2nd one

how many objects are eligible for gabage collection after executing c.aob = null;




in this one object is eligible for GC
that is C object


for easy understanding purpose you can draw each and every object and it references
 
Ademola Okerinde
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot.
information very helpful.

Sorry for repeating question, am new to the forum.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic