如何回收Java线程堆栈使用的内存? [英] How to reclaim the memory used by a Java thread stack?

查看:423
本文介绍了如何回收Java线程堆栈使用的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天来我一直在遇到这个内存泄漏问题,我想我现在有了一些线索.我的 java进程的内存一直在增长,但堆却没有增加.有人告诉我,如果创建多个线程,这是可能的,因为Java线程在堆之外使用内存.

我的java进程是服务器类型的程序,因此有1000-2000个线程.正在进行创建和删除.如何回收Java线程使用的内存?我是否只需擦除对线程对象的所有引用并确保其终止?

解决方案

是.那就是答案.只要有对任何Java对象的有效引用,该对象完成后就不会被垃圾回收. 如果您要创建和销毁线程而不是将它们合并,那么我认为您还有其他问题.

I've been having this memory leak issue for days and I think I have some clues now. The memory of my java process keeps growing but yet the heap does not increase. I was told that this is possible if I create many threads, because Java threads uses memory outside of the heap.

My java process is a server type program so there are 1000-2000 threads. Created and deleted ongoing. How do I reclaim the memory used by a java thread? Do I simply erase all references to the thread object and make sure that this is terminated?

解决方案

Yes. That is the answer. As long as there is an active reference to any Java object, then that object won't be garbage collected when it's done. If you're creating and destroying threads and not pooling them, I think you have other issues as well.

这篇关于如何回收Java线程堆栈使用的内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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