内存泄漏?为什么java.lang.ref.Finalizer吃了这么多内存 [英] is memory leak? why java.lang.ref.Finalizer eat so much memory

查看:5200
本文介绍了内存泄漏?为什么java.lang.ref.Finalizer吃了这么多内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序上运行了一个堆转储。当我在内存分析器工具中打开它时,我发现 java.lang.ref.Finalizer org.logicalcobwebs.proxool.ProxyStatement 占用了大量内存。为什么会这样?

I ran a heap dump on my program. When I opened it in the memory analyzer tool, I found that the java.lang.ref.Finalizer for org.logicalcobwebs.proxool.ProxyStatement was taking up a lot of memory. Why is this so?

推荐答案

某些类实现 Object.finalize()方法。覆盖此方法的对象需要由后台线程调用终结器调用,并且在发生这种情况之前无法清除它们。如果这些任务很短并且您没有放弃其中的许多任务,那么一切都很顺利。但是,如果要创建大量这些对象和/或它们的终结器需要很长时间,则要完成的对象队列会建立起来。这个队列可能会耗尽所有内存。

Some classes implement the Object.finalize() method. Objects which override this method need to called by a background thread call finalizer, and they can't be cleaned up until this happens. If these tasks are short and you don't discard many of these it all works well. However if you are creating lots of these objects and/or their finalizers take a long time, the queue of objects to be finalized builds up. It is possible for this queue to use up all the memory.

解决方案是


  • 如果可以,请不要使用finalize()d对象(如果您正在为对象编写类)

  • make finalize very short(如果必须使用它)

  • 每次都不丢弃此类对象(尝试重复使用)

当您使用现有库时,最后一个选项可能最适合您。

The last option is likely to be best for you as you are using an existing library.

这篇关于内存泄漏?为什么java.lang.ref.Finalizer吃了这么多内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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