• 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
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

garbage collection

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
((You should directly invoke the garbage collection system before entering a time critical section of code.))
Could any one explain to me this statement I could not understand it. if you can with exapmle plez
Thanks in advs
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did that quote come from?
Realize that it's impossible to directly call the Garbage Collector.
from the System.gc()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. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.


[ October 31, 2002: Message edited by: Jessica Sant ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you start to run out of memory in a time critical section of code, garbage collection will possibly start. This may take some time, maybe significantly delaying your thread. So invoking System.gc() before you start yout time critical section may help avoid the memory shortage. But don't rely on it actually causing garbage collection to occur.
Notice all those mays and maybes that's the way garbage collection is.
-Barry
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy -- for the purposes of the exam, I concur with the other folks - NO GUARANTEES. However, in practice, most VMs do respond, so I used it in the past (especially before HotSpot when it *really* made a huge difference) to help prevent the garbage collector from running at an "inappropriate" time. As a game developer then, I defined "inappropriate" as "right in the middle of an intense animation scene." Like, the last thing you want is the guy to be running away from the alien Tiger and then suddenly freeze -- mid-stride -- while gc happens. So I always liked to invoke System.gc() before something that needs to proceed smoothly, OR when I know that the user will not notice. For example, when the user is reading a Help Screen, that is a nice time for gc to happen.
But with HotSpot, this really does not seem to matter much anymore.
I wish I had a garbage collection system at home. But it would have to be smart enough to know that -- even though I still have a live reference to something -- I will never use it/wear it/eat it again if my life depends on it
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kathy Sierra:
I wish I had a garbage collection system at home. But it would have to be smart enough to know that -- even though I still have a live reference to something -- I will never use it/wear it/eat it again if my life depends on it


--dang... that would be wonderful. Maybe you could patent your idea? However... with my luck, when it got in my house when I "suggested" it should run the garbage collector, it would just ignore me and keep getting OutOfMemoryExceptions.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic