• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Garbage Collection strikes again...

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a question I found on a test referenced by jiris.com... called JavaQuestions 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.

I think the correct answer is 'e' only but the author indicates that its b,c,e.
Your thoughts will be greatly appreciated. Thanks in advance...
 
Ranch Hand
Posts: 1055
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


b. You can directly run the garbage collector whenever you want to.


You can suggest to the JVM to run the garbage collector by System.gc(), but that's it.


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


I think this is downright wrong. Maybe it was referring to finalize().
 
Lucy Das
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anthony.. appreciate your help.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I too feel only d is correct ans.
You can directly run the garbage collector whenever you want to. This is not true because u can force JVM to invoke it using System.gc()but when it will run depends on JVM.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lucy Das,
This topic is a bit confusing, but if you go throught the materials carfully.

I think that only cis the right answer.

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

what i think is GC informs your obj means that you can make sure when actually the GC is running.


when comming to the other points.
b --> as java doubts told is correct.
e --> it may be right because it depends on different situation and algorithms


regards

sham
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Lucy:

a. You can directly free the memory allocated by an object.
No way
b. You can directly run the garbage collector whenever you want to.
No, you v=can only request the GC to run. The doc is crystal clear that you can't force the GC to run.
c. The garbage collector informs your object when it is about to be garbage collected.
If they mean finalize(), that does not work if finalize() has already run and cancelled GC eligibility by creating a reference to the object. finalize() is never calleed more than once on any one instance.
d. The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
No, GC may never run at all.
e. The garbage collector runs in low-memory situations.
Yes, this is in the doc. It is not the only time GC runs, but we are told by the API that the jvm runs GC before throwing an OutOfMemoryError.

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.


[ January 22, 2005: Message edited by: Mike Gershman ]
 
And inside of my fortune cookie was this tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic