Theory and algorithm behind Java garbage collection

后端 未结 6 1288
悲哀的现实
悲哀的现实 2021-01-31 05:14

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 implemented?

When and

相关标签:
6条回答
  • 2021-01-31 05:55

    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.

    0 讨论(0)
  • 2021-01-31 05:57

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

    0 讨论(0)
  • 2021-01-31 06:03

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

    0 讨论(0)
  • 2021-01-31 06:07

    The garbage collection technique uses MARK and SWEEP algorithm.

    For more details Mark-and-Sweep Garbage Collection

    0 讨论(0)
  • 2021-01-31 06:11

    ... 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.

    0 讨论(0)
  • 2021-01-31 06:14

    The Wikipedia entry for garbage collection covers all your questions:

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

    0 讨论(0)
提交回复
热议问题