Java垃圾收集背后的理论和算法 [英] Theory and algorithm behind Java garbage collection

查看:88
本文介绍了Java垃圾收集背后的理论和算法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在很多地方阅读过,但没有找到一个我可以学习的地方:

什么是Java垃圾收集的全部内容?

它是如何实现的?

何时以及如何调用?

为了回收内存,以下算法如何?



简而言之,它就是它的一切:)

固定!!!



一篇非常好的文章: http:/ /www.artima.com/insidejvm/ed2/gcP.html

解决方案

答案的简短版本是:


什么是所有
的java垃圾回收?


GC是内存管理的一种机制,系统(本例中为JVM)负责自动回收不再使用的内存。


它是如何实施的?

有多种方式来实现它。一个简单的描述是,每个分配的内存都被跟踪。系统会定期检查分配的部分,以查看程序的任何部分(变量)是否仍然可以到达内存。


何时以及如何调用?


这也由实施决定。 Java中唯一的保证是在引发OutOfMemoryError之前,系统将尝试回收内存。我希望大多数GC实现也会在向底层操作系统请求更多内存之前尝试进行收集。通常会有一个后台线程处理运行收集器。


为了
回收内存

有几种可能的。看看其他人发布的文章作为开始。


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

这篇关于Java垃圾收集背后的理论和算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆