[英]Java - ThreadFactory memory leak?
This code: 这段代码:
while (true) {
new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return null;
}
};
}
make the JVM go out of memory very quickly. 使JVM非常快地耗尽内存。
Why? 为什么?
I have tried to run this code with JRE 1.7.0_60 x86_64 on Windows 7 with default options and here are the results: 我尝试使用默认选项在Windows 7上使用JRE 1.7.0_60 x86_64运行此代码,结果如下:
threadFactory
s to System.out
results in "saw-like" heap usage pattern: 将创建的threadFactory
输出到System.out
的代码的修改版本导致“锯状”堆使用模式: Which means that both allocation and garbage collection takes place. 这意味着分配和垃圾回收都会发生。
Back to your question: I think you missed some significant parts of the code, or put -Xmx to extremely low value, or some other reason. 回到您的问题:我认为您错过了代码的重要部分,或者将-Xmx设置为极低的值,或者是其他原因。 The code you posted is ok, though. 不过,您发布的代码还可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.