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

Another question on GC

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello experts,
Put some more light on option b.Tell us it's correct or not.
 
Sharmila Abkari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

reply
    Bookmark Topic Watch Topic
  • New Topic