垃圾收集者的机会 [英] garbage collector opportunity

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

问题描述

大家好,
我刚刚阅读了有关Java垃圾收集器的信息,并有一些与之相关的问题:
这些引用是什么意思:

Hi All,
I''ve just read about Java garbage collector and have some question associated with it :
What mean these quotation :

"Java’s garbage-collection mechanism may recover only memory that is definitely
unused. It is not possible to force garbage collection reliably. It is not possible 
to predict when a piece of unused memory will be collected, only to say when it 
becomes eligible for collection.  Garbage collection does not prevent memory leaks; 
they can still occur if unused references are not cleared to null or destroyed."

推荐答案

例如,请参见:
See, for instance: Handling memory leaks in Java programs[^].


垃圾回收可以在JVM上进行调整-请参见
Garbage collection can be tuned on the JVM - see this article[^] - rather then in code. You can call collection from code but it is not the best approach as the JVM is, at the end of everything, the final arbiter of what is garbage.

To answer the individual points:

arsenk02写道:
arsenk02 wrote:

Java的垃圾回收机制只能恢复绝对未使用的内存.

Java’s garbage-collection mechanism may recover only memory that is definitely unused.


当无法再访问对象时,它将变为可收集".在这种情况下,这意味着可以从活动线程进行访问.这很重要,因为它允许收集循环对象,请参见以下内容:


When an object can no longer be accessed it becomes ''collectable''. In this it means accessible from a live thread. This is important as it allows for cyclicle objects to be collected, see the following:

Foo a = new Foo();
Foo b = new Foo();
a.setBar(b);
b.setBar(a);
// now (a) references (b) and (b) references (a)
a = null;
b = null;
// the objects, though still referenced cannot be reached so are good to go





arsenk02写道:
arsenk02 wrote:

不可能可靠地强制进行垃圾收集.

It is not possible to force garbage collection reliably.


集合特定于JVM.关于可以收集什么的规则,但是没有如何获取的规则.


Collection is specific to the JVM. There are some rules about what can be collected, but not how.

arsenk02写道:
arsenk02 wrote:

无法预测何时将收集未使用的内存,而只能预测何时有资格进行收集.

It is not possible to predict when a piece of unused memory will be collected, only to say when it becomes eligible for collection.


再次,程序员不知道哪个JVM将运行,因此您无法确切地说出收集的方式或时间.在大多数JVM中,收集是在单独的GC线程上完成的,该线程试图减少对运行时的影响,从而在收集频率和可用内存量之间做出折衷.如果您为JVM分配了很多内存,那么它就不会因为不需要而频繁地收集内存.



Again, the programmer does not know which JVM will be running and so you cannot say precisely how or when collection will take place. In most JVM''s the collection is done on a separate GC thread that tries to reduce the impact on the runtime making a compromise between the frequency of collection and the amount of available memory. If you allocate a lot of memory to your JVM, it won''t bother collecting too often as it won''t need to.


arsenk02写道:
arsenk02 wrote:

垃圾回收并不能防止内存泄漏.如果未使用的引用未清除为null或销毁,它们仍然会发生.

Garbage collection does not prevent memory leaks; they can still occur if unused references are not cleared to null or destroyed.


如果您引用的对象仍可访问,则将不会收集该对象,否则将不会收集该对象.因此,如果您习惯于创建很多功能对象,这些对象要等到它们完成才完成,但实际上从未完成,这会导致内存泄漏.

我的建议是阅读您所指向的文章,如果仍然有问题,请在您的应用程序上放置一个监视器,例如
jconsole [ ^ ]并观察内存将要到达的位置.


If you have a reference to an object that is still accessible it will not be collected, it can''t be. Soo if youare in the habit of creating lots functional objects that get held until they finish, but never actually complete, you''ll run into memory leak.

My advice is to read the articles you''ve been pointed to and if you are still concerned, put a monitor on your app, such as jconsole[^] and watch where the memory is going to.


有一些标识,JVM会使用这些标识来清理未使用的内存.

请参阅此链接.


http://www.artima.com/insidejvm/ed2/gcP.html [ ^ ]
there is some alogorithm which is used by JVM to clean unused memory.

see this link.


http://www.artima.com/insidejvm/ed2/gcP.html[^]


这篇关于垃圾收集者的机会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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