Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Help! GC question #1.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • Quote
  • Report post to moderator
i think david is right....
 
Xiao Hu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David, I think you are right
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic