视觉VM强制GC

发布于 2024-09-27 06:22:14 字数 312 浏览 1 评论 0原文

  1. 我对 POJO 的内存使用情况进行采样并计算实例数量。如果当我在视觉虚拟机中按“垃圾收集”并且我可以看到实例关闭时,这是否意味着它没有内存泄漏?

  2. 如何强制jvm每天午夜进行垃圾收集? (就像在 VisualVM 上自动按垃圾收集一样)?我看到 VisualVM 的 cpu 使用率,gc 始终为 0%。我设置了-xmx -xms 1024m,但通常内存使用量在200mb左右。这是因为 GC 仅在必要时才进行吗?这就是为什么 gc cpu 时间总是 0%

  3. 如何检查上次执行“full GC”的时间?

  1. i sampling the memory usage and count number of instances for POJO. if when i press 'garbage collecting' in visual vm and i can see the instances down , does that mean it's memory leak free ?

  2. how to force jvm do garbage collecting everyday at midgnight ? (just like automatically press garbage collect on visualvm) ? i see visualvm 's cpu usage, gc is always 0%. i set -xmx -xms 1024m, but normally memory usage around 200mb. is this because GC is only done when necessary? that's why always 0% for gc cpu time

  3. how to check the time of last time doing 'full GC' ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾夏年华 2024-10-04 06:22:14
  1. 不,不一定。这真正意味着您的一些对象可以被收集。例如,如果实例计数在 GC 之后总是下降,但又不完全达到之前的水平,那么您仍然可能会出现垃圾泄漏;如果这个“基线”随着时间的推移而增加,你偶尔会耗尽内存。此外,很难证明是否定的,因此您的应用程序可能确实存在内存泄漏错误,但这种特定情况并未发挥作用。
  2. 让我们澄清一件事 - 你永远不能强制 JVM 运行垃圾收集。您能做的最好的事情就是调用System.gc(),这是一个提示给 JVM 它现在可能想要运行 GC。它不需要做任何事情,并且该方法的无操作实现将是完全有效的。基本上,垃圾收集“自然而然地发生”,并且您对它的特定期望越少越好。所以基本上,是的,它通常只会在需要时运行。
  3. 同样,这通常是内部知识,详细信息将取决于您使用的垃圾收集器实现。然而,对于 Sun 的 JVM,您可以使用命令行参数 -verbose:gc 将详细的垃圾收集详细信息输出到控制台。如果您想以编程方式或视觉方式检查详细信息,此信息也可能通过 JMX 公开(即 设置您的流程以使用 JMX 远程处理,并使用 JConsole 连接到它)。对于我来说,使用 Sun 的 1.5.0_06 JVM,我在 java.lang.GarbageCollector 中看到一个 MBean,它公开了一些信息,包括上次完整 GC 的时间。
  1. No, not necessarily. All that really means is that some of your objects can be collected. You could still have a garbage leak if, for example, the instance count always went down after a GC but not quite to the same level as before; if this "baseline" increased over time you'd run out of memory occasionally. Also, it's very hard to prove a negative, so it could be that your application does have a memory leak bug, but this specific situation isn't exercising it.
  2. Let's clarify one thing - you can never force the JVM to run garbage collection. The best you can do is call System.gc(), which is a hint to the JVM that it might want to run GC now. It doesn't have to do anything, and a no-op implementation of that method would be perfectly valid. Basically, garbage collection "just happens" and the less you place specific expectations on it the better. So basically, yes, it will typically only run when needed.
  3. Again, this is typically internal knowledge and the details will depend on which garbage collector implementation you're using. For Sun's JVM, however, you can use the command-line argument -verbose:gc to get verbose garbage collection details output to the console. If you want to inspect the details programmatically or visually, this information might be exposed via JMX too (i.e. set up your process to use JMX remoting, and connect to it with JConsole). For me, using Sun's 1.5.0_06 JVM, I see an MBean in java.lang.GarbageCollector that exposes some information including the time of the last full GC.
春夜浅 2024-10-04 06:22:14
  1. 没有。没有真正具体的方法来确定您的应用程序是否没有内存泄漏。最好的方法是长时间运行浸泡测试,并确保活动堆的大小稳定。

  2. 您可以使用 System.gc() 方法调用来运行垃圾收集器。

  3. 似乎没有 API 可以获取上次 GC 运行的时间,但是 GarbageCollectorMXBean 可以提供一些有关 GC 的统计信息。

  1. No. There is no really concrete way to determine if your application is memory leak free. The best is to run a soak test over an extended period of time and ensure that the size of the live heap is stable.

  2. You can use the System.gc() method call to run the garbage collector.

  3. There doesn't seem to be an API for getting the last time a GC has run, however the GarbageCollectorMXBean can give some statistics about the GC.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文