简体   繁体   English

Java堆内存使用量增加

[英]Java heap memory usage increases

I was doing a quick experiment to see how my algorithm's memory performance looks like. 我正在做一个快速的实验,看看我的算法的内存性能如何。 The input is about 2 Mb and the algorithm takes about 1 second to run it. 输入大约为2 Mb,算法运行大约需要1秒。 I ran this in a loop for 500 times to be able to look at the memory allocation. 我在循环中运行了500次,以便能够查看内存分配。

This is how jConsole shows the memory usage: 这是jConsole显示内存使用情况的方式:

在此输入图像描述

As you can see heap memory usage increases (kinda exponentially) every two times before GC starts (even though the input is the same). 正如您所看到的那样,在GC启动之前,堆内存使用量每两次增加(有点指数)(即使输入相同)。

Does anybody know if this is expected and why it happens? 有人知道这是否是预期的以及为什么会发生这种情况? Is it some optimization done by JVM? 它是由JVM完成的一些优化吗?

Thanks! 谢谢!

Does anybody know if this is expected and why it happens? 有人知道这是否是预期的以及为什么会发生这种情况? Is it some optimization done by JVM? 它是由JVM完成的一些优化吗?

The JVM is trying to minimise the time spent GC-ing. JVM正在尝试最小化GC-ing所花费的时间。 If you use more memory, it doesn't have to GC as often. 如果使用更多内存,则不需要经常使用GC。

a leak? 泄漏?

If you look at memory usage after a GC it is much the same so clearly it doesn't have a memory leak. 如果你看一下GC之后的内存使用情况,它就会大致相同,所以很明显它没有内存泄漏。 Or at least not a big one. 或者至少不是一个大的。

You have to look at the memory used after Full GCs to confirm there is a memory leak and I assume these are minor collections. 您必须查看Full GCs之后使用的内存以确认存在内存泄漏,并且我认为这些是次要集合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM