Java 中的循环引用 [英] Circular References in Java

查看:35
本文介绍了Java 中的循环引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以复杂的循环方式相互引用的类实例的聚合:垃圾收集器是否可能无法释放这些对象?

Given an aggregation of class instances which refer to each other in a complex, circular, fashion: is it possible that the garbage collector may not be able to free these objects?

我依稀记得这是过去 JVM 中的一个问题,但我认为这在几年前就已经解决了.然而,在 jhat 中的一些调查显示,循环引用是我现在面临的内存泄漏的原因.

I vaguely recall this being an issue in the JVM in the past, but I thought this was resolved years ago. yet, some investigation in jhat has revealed a circular reference being the reason for a memory leak that I am now faced with.

注意:我一直认为 JVM 能够解析循环引用并从内存中释放此类垃圾岛".但是,我提出这个问题只是想看看是否有人发现了任何异常.

推荐答案

只有非常幼稚的实现才会出现循环引用问题.维基百科有一篇关于不同 GC 算法的很好的文章.如果你真的想了解更多,试试(亚马逊)垃圾收集:自动动态内存管理算法.Java 从 1.2 开始就有一个很好的垃圾收集器,在 1.5 和 Java 6 中也有一个非常好的垃圾收集器.

Only a very naive implementation would have a problem with circular references. Wikipedia has a good article on the different GC algorithms. If you really want to learn more, try (Amazon) Garbage Collection: Algorithms for Automatic Dynamic Memory Management . Java has had a good garbage collector since 1.2 and an exceptionally good one in 1.5 and Java 6.

改进 GC 的难点在于减少暂停和开销,而不是循环引用等基本内容.

The hard part for improving GC is reducing pauses and overhead, not basic things like circular reference.

这篇关于Java 中的循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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