• 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

Marcus3 q49

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q49 of Marcus's third exam is as follows:


Which of the following statements are true?
1) The automatic garbage collection of the JVM prevents programs from ever running out of memory
2) A program can suggest that garbage collection be performed but not force it
3) Garbage collection is platform independent
4) An object becomes eligible for garbage collection when all references denoting it are set to null.


The correct answers, according to Marcus are: 2) and 4).
Surely 4) is not a correct answer as an object is eligible for garbage collection when all references to it are set to denote another object, or to null?
Siobh�n
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Siobhan,
Can you tell me why no.4 is not correct
I feel it is right. If there is no reference pointing to that object then it is ready for GC.

Indu
 
Siobhan Murphy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indu
Thanks for your response.
For example, say you create 2 objects a and b, where a denotes one object and b denotes another.
After line 3 below, a denotes the same object as b, but there is no reference to the object denoted by a originally. Therefore the object denoted by a is now eligible for garbage collection. Isn't it? The object is no longer accessible. In this example there was no expression setting anything to null.
I'd be glad if someone could clear this up for me, as I thought I understood the concept.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you may be answering a different question to the one I was asking. I asked if the statement was true that...
An object becomes eligible for garbage collection when all references denoting it are set to null.

Whereas you appear to be answering the question is it true that
"The only circumstances under which an object becomes eligible for garbage collection is when all references denoting it are set to null"..
Not the addition of "The only circumstances etc etc"..
Subtle but important.
Marcus

------------------
http://www.jchq.net Mock Exams, FAQ, Tutorial, Links, Book reviews
=================================================
Almost as good as JavaRanch
=================================================
 
Siobhan Murphy
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response Marcus.
When I was doing the exam I thought the question was:
"Is it true that an object becomes eligible for garbage collection when all references denoting it are set to null, and this is the only way. Setting a reference to another object just isn't enough"
When answering it I thought: Not true, there are other ways of making an object eligible for gc, e.g. setting any references to it, to other objects.
Incidently, thanks for your 3 sets of exams. I found them very helpful, and I learnt a lot from them.
 
You showed up just in time for the waffles! And this tiny ad:
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