• 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

about garbage collectiion

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 memory as soon as it becomes a candidate for garbage collection.
e) The garbage collector runs in low-memory situations
answer:ade
I think a is not right.help me!
[ December 07, 2002: Message edited by: feng lee ]
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is c. Maybe e. I am not sure of e. someone pls correct me.
a) You can directly free the memory allocated by an object.
-----You can't directly free the memory. Only garbage collector can do this. You can only make the object eligible for garbage collection.
b) You can directly run the garbage collector whenever you want to.
-----You can't run the garbage collector whenever you want to. Garbage collector is a low priority thread. You dont have any control on this.
c) The garbage collector informs your object when it is about to be garbage collected.
-----I think this is true since the finalize() method will be executed before garbage collecting.This will be a notification for the object.
d) The garbage collector reclaims an object memory as soon as it becomes a candidate for garbage collection.
----GC is a low priority thread and we dont have any control on when it will run to reclaim all the eligible GC'ed objects.
e) The garbage collector runs in low-memory situations.
I think its true. I dont have much explanation..Pls someone add more to this.
Thanks
Ramki.
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Although answer e might describe the actual operation of some implementations of the garbage collector I believe that it is not a good answer for the real exam. The exam does not test your knowledge of the actual behavior of "some" implementations of the garbage collector. Instead, the exam tests your knowledge of the guaranteed behavior of any garbage collector and running in low memory situations is not guaranteed.
What is guaranteed is the points at which an object can become eligible for garbage collection. The point in time when the garbage collector actually runs in not guaranteed.
One invocation of the finalize method is also guaranteed. Correction: One invocation of the finalize method is guaranteed before the object is garbage collected. However, there is no guarantee that an object will be garbage collected before the program terminates.
If I forgot any guarantees or non-guarantees then please add to the list.
[ December 07, 2002: Message edited by: Dan Chisholm ]
 
ramki srini
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So Dan, whats the answer?
Is it only 'c'.
Then fenn from where u get this question which says the answer a,d,e...
Thanks
Ramki
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, C is correct. The garbage collector invokes the finalize method before the memory is reclaimed.
 
feng lee
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a friend give me the mock.It do has some mistakes.Dan,I want to ask that if we can call the finalize() method explicitly.thus,when the garbage collector reclaims the object the finalize() method will be invoked again.is that right?
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic