Win a copy of Getting started with Java on the Raspberry Pi this week in the Raspberry Pi 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Liutauras Vilda
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Piet Souris

Garbage Collection - Boone's Mock Q

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 65: Which statements about garbage collection are true?
Select all valid answers.
(a)You can directly free the memory allocated by an object.
(b)You can directly run the garbage collector whenever you want to and it will be schedule in due time..
(c)The garbage collector informs your object when it is about to be garbage collected.
(d)The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
(e)The garbage collector runs in low-memory situations.
Ans given : b, c and e
Question 65: b, c, e. You cannot directly free the memory allocated by an object, though you can set an object reference to null. Also, The garbage collector only runs in low-memory situations, and so does not always reclaim an object�s memory as soon as it becomes a candidate for garbage collection.
I agree with C and E but what about B?
The exact wording of B seems ambiguos, because you can suggest GC and it may run eventually, or may not at all! The wording "can run" seems to make it false!
Am I right?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would agree that B is false. Unless they consider suggesting the garbage collector run as directly running the garbage collector. Garbage collection may happen in due time, but you can't directly make the vm garbage collect.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I feel that B is true because when the garbage collector is run using the command, the system schedules it for garbage collection but the time when it is be executed is not known.
So, by the ststement "you can run it whenever u want" the meaning is " run the command to schedule it for gc"...
just a thought...
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After careful reading, I think option B is correct. When you called System.gc(), you know it will run in future. Although the exact time is unknown, you may say it is "scheduled".
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Charles Leung:
After careful reading, I think option B is correct. When you called System.gc(), you know it will run in future. Although the exact time is unknown, you may say it is "scheduled".

I disagree. It is not necessarily scheduled, and you are given no guarantees whatsoever that it will actually run before termination of the program. The only garbage collection guarantee the Java language gives you is that the garbage collector will run before an OutOfMemoryError is thrown.
Option B, IMHO, is blatantly incorrect. You cannot "directly run the garbage collector whenever you want to". The best you can do is "suggest that the Java virtual machine expend effort toward recycling unused objects".
- Peter
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The wording of the option B is ambiguous as it attempts to join 2 totally contradictory statements with a conjunction.
The first part

You can directly run the garbage collector whenever you want to


attempts to suggest that you can invoke GC any time.. which FALSE. We can only "request" JVM to "run" GC.
While the second part

it will be schedule in due time


conveys the right and is TRUE.
So, in totality, it seems to me, that the answer is FALSE [ after all TRUE AND FALSE will give FALSE].
We can only hope such ambiguous statements do not appear in the exam
 
Charles Leung
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter & Neeraj, I agree
thanks you
 
Peter den Haan
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before deciding whether the second part is true, I wonder what exactly does it mean? Do you have any guarantees that the garbage collector is "scheduled" as such (apart from the concept of general thread scheduling, which is probably not meant here)? What exactly is "due time"? After all, the only real guarantee you have is that the garbage collector will run (not: be scheduled) before an OutOfMemoryError is thrown.
Even taken in isolation the second half seems very ambiguous and ill-defined. It can be given a valid meaning, as you do (and there's nothing wrong with that!), but it can easily be interpreted in ways that are not valid at all. At best, we can assign it an UNDEFINED truth value or throw an AmbiguousQuestionException
If my experience is anything to go by, the exam is much more carefully worded.
- Peter
[ April 10, 2003: Message edited by: Peter den Haan ]
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

(c)The garbage collector informs your object when it is about to be garbage collected.


Can someone explain what does (c) exactly mean? Thanks.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lih Wang:

Can someone explain what does (c) exactly mean? Thanks.


Basically, that means that the garbage collector will give your object some warning that it is about to be garbage collected. In this case, that warning takes the form of invoking the object's finalize method. That method gives the object a chance to "clean up" anything that it needs to before it is obliterated.
I hope that helps,
Corey
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Low Tech Laboratory
https://www.kickstarter.com/projects/paulwheaton/low-tech-0
reply
    Bookmark Topic Watch Topic
  • New Topic