File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Another question on GC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Another question on GC" Watch "Another question on GC" New topic
Author

Another question on GC

sajida kal
Ranch Hand

Joined: Mar 22, 2001
Posts: 89
Q65 from Barry Boones mock exam.
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.
Correct answers according to the mock are b,c,e.
I have a few questions here-
b. This seemed to be an incorrect option to me. GC can be invoked anytime by a program, but whether it runs or not, is entirely upto the JVM. So why is b a correct answer.
c. I read somewhere that the finalize method is called for an
object only once. If, in the finalize method, we 'revive' the reference again, then if gc is invoked a second time, the finalize method will not be called. If the above is true, then c does not seem to be a valid option.

Would appreciate if anyone could comment on this.
Thanks
Sajida
Sharmila Abkari
Greenhorn

Joined: Mar 29, 2001
Posts: 15
option (b) is correct because
u can call the method System.gc() to run garbage collector at any point you choose, but that doesn't mean you will get it.
Sharmila Abkari
Greenhorn

Joined: Mar 29, 2001
Posts: 15
option (c) is correct because
The gc will usually call an object's finalize() method just before the object is gc-ed .
And any object is garbage collected only once.
Please correct me if i am wrong.
nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
Hello experts,
Put some more light on option b.Tell us it's correct or not.
Sharmila Abkari
Greenhorn

Joined: Mar 29, 2001
Posts: 15
Originally posted by nitin sharma:
Hello experts,
Put some more light on option b.Tell us it's correct or not.


Nitin,
I am no expert , but i found the same q's in a old quote: Topic: Gc question
posted December 25, 2000 07:45 PM
and
Topic: garbage collection
posted December 26, 2000 10:13 PM
this has lot of discussion on this topic.
u can search for it.
Regards
Sharmila

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Another question on GC
 
Similar Threads
GC
Garbage Collection strikes again...
Garbage Collection
garbage collection
a question about GC