• 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
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Doubt related to Garbage Collection Questions

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

This is a question from Devaka's final exam.

How many objects are eligible for GC after line 17?

1. class A{
2. A a1;
3. A a2;
4. public void finalize(){
5. System.out.println("A");
6. }
7. public static void main(String args[]){
8. A a1=new A();
9. A a2=new A();
10. a1.a1=new A();
11. a2.a2=new A();
12. a1.a2=new A().a1;
13. a2.a1=a1;
14. a2.a1.a2=new A();
15. a1.a1.a1=new A();
16. a1=null;
17. a2=null;
18. System.gc();
19. }

The answer is 7.

Can someone tell me how should we work out these types of questions related to GC?
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
5 minutes drawing circles reperesnting objects and arrows representing references and you will figure it out.
But I wonder - do they have questions like this on the real exam?
 
Aditi Roychoudhury
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alexander,

Thanks for the reply.

Can anyone confirm if questions of this type are present in the SUN exam?Also,any different approach to tackle this question?

Thanks,
Aditi.
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alexander advice is a very good advice to tackle this kind of questions.

Greetings.
 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once you see such a question get ready with a pen and paper. draw the diagram then these question are very simple.
In the actually exam i dont think such a complex question will not be given, but a simple question would be given.But expect the unexpected.
Remember diagram solves the even a complex question
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic