Re: What Garbage Collectors Do
Attila Szegedi <[email protected]> Thu, 5 Jun 2008 17:45:54 +0200
| Newsgroups | gmane.comp.windows.devel.java.advanced |
|---|---|
| Message-ID | <[email protected]> |
Well, in terms of the process' memory, a garbage collector needs to establish which regions of allocated memory represent live objects, and which regions of allocated memory represent dead objects. Since the two sets complement each other, it is sufficient to determine one of the two sets. Indeed most garbage collectors will traverse the graph of live objects starting from the known roots, and release some or all of the memory regions not traversed. Some collectors are compacting or copying, where they'll move the set of live objects to compactly fill the bottom of the heap (or copy all of them to a newly allocated space), and then release anything above the new heap top (or the whole old space, this is referred to as a "sweep"). Modern JVM GCs will maintain several (often two) "generations" in the heap, with newly created objects going to "young" generation, which is collected more often. Objects surviving few GC cycles are promoted to the "tenured" generation, which is collected less often. This way, the set of stable objects in your program will burden the GC less. There's often even a small younger-than-young generation called "eden", divided into two spaces, that uses a mark-and-sweep copying strategy, while the young and tenured generations use a compacting algorithm instead. The eden is meant to make it inexpensive to have lots of short-lived allocated objects, the tenured generation is meant to make it inexpensive to have lots of long-lived objects. Yes, automatic memory management is indeed close to rocket science nowadays; I'm admittedly just an enthusiastic amateur when it comes to understand it :-) I like the term "garbage collector" though. Beats "automatic memory deallocator" any day :-) Attila. On 2008.06.05., at 17:16, Randall R Schulz wrote: > Hi, > > Someone in the Scala-Debate list posted this amongst a discussion > about > about how upcoming (proposed) improvements to the JVM might benefit > Scala: > > On Thursday 05 June 2008 07:33, Nils Kilden-Pedersen wrote: >> It's a common misconception that the GC needs to clean garbage. The >> GC is limited by live objects, not dead. The term "garbage collector" >> is truly a misnomer with current implementations as it is not garbage >> that is being collected, but non-garbage, i.e. live objects. > > > How accurate / complete is this notion? It does not seem entirely > sensible to me. > > > Randall Schulz =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com