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

GC

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a question from anilbachi news letter 19.
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.

I would say b & c are correct.
But the solution is b, c, e.
howz e possible when u cannot guarantee that it runs.
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lakshmi,
I am quoting a sentence from Khalid Mughals book (A Programmers guide to Java Certification) which says " Garbage collector will certainly go to work if there is a danger of running out of memory."
I guess thats why option e is also valid answer.
HTH....
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hold on, I thought that you can not make the Garbage Collector run. You can "suggest" the JVM to put effort towards object recycle via System.gc() & Runtime.gc(). See RHE, pg. 21.
so b is not a correct choice(Let me know if I overlooked something).
Even e is not guaranteed. So, I think the only correct choice is c.
 
lakshmi nair
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i thought by selecting option b is that you can always run (or better call) System.gc(), though it is not for sure that the objects will be garbage collected.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe 'e' is correct also.
The garbage collector may run at low memory state... or may not, if there's nothing to free up. This doesn't make 'e' false.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I would say only options c and e are correct.
a) false
You cannot directly free memory allocated by an object.
b) false
There is no guarantee that the garbage collector will run when you call the <code>System.gc()</code> or <code>Runtime.gc()</code> method. The documentation for the <code>gc</code> method states:

"Calling this method suggests that the JVM expends effort towards recycling unused objects."


c) true
The garbage collector calls <code>finalize</code> on an object. The SDK documentation on finalize states:

"Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. A subclass overrides the finalize method to dispose of system resources or to perform other cleanup."


d) false
There is no guarantee that the garbage collector will reclaim the object memory as soon as it becomes garbage collectable.
e) true
If you look at the OutOfMemoryError class description in the SDK documentation, it says:

"Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector."


This means that the garbage collector will run in low-memory situations.
Cheers,
Beno�t
[This message has been edited by Beno�t d'Oncieu (edited November 01, 2000).]
 
Is that a spider in your hair? Here, threaten it with this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic