• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Boon's Mock Exam Q.65_Garbage

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pl. suggest . . .
The foll Q. is from Boon's Mock Exam.
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.
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, e.
But in my opinion only e is the ans.Can anybody there who can put light on the
Above question ?
Thanx,
Vikas
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is only a partial answer to your question. If anyone else has an answer it would be helpful.
The garbage collector for an object can be requested to be run by the programmer, but we do not know for a fact when it will run. The way to run it is with the gc method of the system class or runtime class. (System.gc() Runtime.getRuntime().gc().
As to the object being informed of garbage collection before being collected, I was not aware of that. The only thing I know of is the finalize method. Which is invoked to clean up any operating system resources that you want before the objects are garbage collected. The finalize method is invoked after an object has no references and before actually reclaiming the memory.
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
I think Barry Boone is making a mistake.In his book pg 116 he says that by the time runtime's gc() returns your object will be Garbage collected.
I'll trust Bruce Eckel for that !You have no control over Garbage Collection.
So answer b is surely wrong.
The Garbage Collector is guarenteed to call finalize on every object prior to actually GCing them.
Also the GC runs on low memory situations only.Which is why it is said that you can hardly influence or predict when anything will be Collected.
So the other two options are correct.
 
Ranch Hand
Posts: 625
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This type of question has been debated many times in this forum.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C is definatley correct. How else would your object know to run it's finalyze method if it wasn't informed it was about to be garbage collected.
I do agree that B is incorrect, should state you can directly ask the GC to run, but not you can directly run it.
Bill
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic