开发者

Theory and algorithm behind Java garbage collection

I read at many places, but did not find a place where I can learn about :

What is java garbage collection all about?

How is it impleme开发者_开发问答nted?

When and how is it called ?

What algorithms if follows in order to reclaim memory ??

In short everything about it :)

FIXED!!!

A very good article : http://www.artima.com/insidejvm/ed2/gcP.html


The very short version of answers are:

What is java garbage collection all about?

GC is a mechanism of memory management where the system (the JVM in this case) is responsible for automatically reclaiming memory that is no longer in use.

How is it implemented?

There are various ways to implement it. A simple description is that each piece of memory that is allocated is tracked. periodically the system checks the allocated pieces to see if any part of the program (the variables) can still reach the memory. Any memory that cannot be reached is reclaimed.

When and how is it called ?

This is also left up to the implementation. The only guarantee you have in Java is that before an OutOfMemoryError is thrown the system will attempt to reclaim memory. I would expect that most GC implementations also try to do a collection before they ask the underlying operating system for more memory. In general there will be a background thread that deals with running the collector.

What algorithms if follows in order to reclaim memory ??

There are several possible ones. Look at the articles others have posted as a starting point for that.


The Wikipedia entry for garbage collection covers all your questions:

http://en.wikipedia.org/wiki/Garbage_collection_(computer_science)


... In short everything about it :)

If you have access to a good library, checkout this excellent and comprehensive book on garbage collection:

Richard Jones and Rafael Lins, Garbage Collection: Algorithms for Automatic Dynamic Memory Management, Wiley and Sons (1996), ISBN 0-471-94148-4

Furthermore, this book it is still in print, and listed on at least one well known online bookstore. Shop around. It is available new for a wide range of prices, and for as low as $25 US second hand.


Sun^H^H^HOracle has extensive documentation on the subject.


The garbage collection technique uses MARK and SWEEP algorithm.

For more details Mark-and-Sweep Garbage Collection


Better article for how GC works in Java at JavaRevisted And Algorithem you can get at wiki as mentioned by Dan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜