• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Help! GC question #1.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, guys, I collect some questions on GC from web, but my answers are different from given ones.
PLEASE HELP!!!

=======================================================
This is Question1:

12.void start(){
13. A a = new A();
14. B b = new B();
15. a.s(b);
16. b = null;
17. a = null;
18. System.out.println("start completed!");
19.}

When is the B object, created in line 14, eligible for garbage collection?

A. after line 16
B. after line 17
C. after line 18(When the method ends)
D. There is no way to be absolutely certain.
E. The object is NOT eligible for GC.

The given answer is C, But I think it should be B.
========================================================

I will start a new thread for question 2.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this and let me know if you're still confused.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer should be D becuase in line 15 it pass the reference to object B to a method s. If inside method s it pass the reference to a thread it will make object B ineligible for GC until the thread terminates. However, without seeing the code of method s, there is no way to determine what happens to the reference B.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think david is right....
 
Xiao Hu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David, I think you are right
 
What a stench! Central nervous system shutting down. Save yourself tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic