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

garbage collection

 
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 all
Here is a question from the Barry Boone.
I am not agreed with some of the answers. The answer in the bracket are the answers according to to author.
"Which statements about garbage collection are true? "
Select all valid answers.
1.You can directly free the memory allocated by an object.(false)
(I agree with this)
2.You can directly run the garbage collector whenever you want to. (true)
(I agree with this)
3.The garbage collector informs your object when it is about to be garbage collected. (true)
(I agree with this)
4.The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
(I agree with this)
5.The garbage collector runs in low-memory situations. (true)
(I disagree with this, coz it is not a necessary condition)
Can anybody put some light on last point.
Thanks
Shikhar
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I will like to correct you on 2nd point
we cannot directly run garbage collector
we can only suggest to the system and it is upon the system to decide when the garbage collector is to be run
about 5th point you are right if it was written
that it may run in low-memory situations than 5 would be correct
actually it is a low priority thread and depends upon the system
when that thread will get chance to execute
that is why it is not necessay condition

Originally posted by shikhar:
Hi all
Here is a question from the Barry Boone.
I am not agreed with some of the answers. The answer in the bracket are the answers according to to author.
"Which statements about garbage collection are true? "
Select all valid answers.
1.You can directly free the memory allocated by an object.(false)
(I agree with this)
2.You can directly run the garbage collector whenever you want to. (true)
(I agree with this)
3.The garbage collector informs your object when it is about to be garbage collected. (true)
(I agree with this)
4.The garbage collector reclaims an object�s memory as soon as it becomes a candidate for garbage collection.
(I agree with this)
5.The garbage collector runs in low-memory situations. (true)
(I disagree with this, coz it is not a necessary condition)
Can anybody put some light on last point.
Thanks
Shikhar


 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah Gaurav, I agree with you and not with the second point
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gourav,
If we cannot run garbage collector, could you please explain me the use of 'System.gc()'
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
I'll quote the API...
Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse.
I hope this clears your doubt.
Regards,
Jayesh.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well as long as you're quoting the API, why not include the very first line of the description for System.gc(): "Runs the garbage collector." And the third sentence: "When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects." The way I see, it, you are running the garbage collector the moment you call System.gc(). You can't guarantee that it will produce any concreate results - the call may return without accomplishing anything. But it will at least try, and that "trying" constitutes "running" as far as I'm concerned. However, the word "run" seems to mean different things to different people, and this particular question is impossible to really answer definitively because there is no agreement as to what it really means. Fortunately, it has been reported that real test questions on this topic are much less ambiguous, so don't worry too much about it.
reply
    Bookmark Topic Watch Topic
  • New Topic