简体   繁体   English

java.exe进程使用更多内存而不释放它

[英]java.exe process uses more memory and does not free it up

I have a java application which when in idle state before any complex executions, uses 23 MB in Heap and the java.exe process size in TaskManager was around 194 MB. 我有一个java应用程序,在任何复杂执行之前处于空闲状态时,在Heap中使用23 MB并且TaskManager中的java.exe进程大小约为194 MB。 After some complex operations, the size of java.exe grew up to around 500MB and the heap size also grew up. 经过一些复杂的操作后,java.exe的大小增长到大约500MB,堆大小也增长了。 The Heap size is reduced back to 23MB after a few full GC by calling System.gc() method. 通过调用System.gc()方法,在几个完整的GC之后,堆大小减少到23MB。 But the size of java.exe reduced to around 237MB from around 600MB which still have around 43 MB of data in it. 但java.exe的大小从大约600MB减少到大约237MB,其中仍有大约43 MB的数据。 Is there a way to reduce this? 有没有办法减少这个? Or is that due to some behavior? 或者是由于某些行为?

This is normal, don't worry. 这很正常,不用担心。 JVM acquires memory when it needs to execute some complex logic. JVM在需要执行某些复杂逻辑时获取内存。 When java is done processing the tasks the JVM will still keep that memory as a reserved space and is not released back to the OS. 当java完成处理任务时,JVM仍将该内存保留为保留空间,并且不会释放回操作系统。 This architecture helps in performance because JMV does not have to request the same memory again from the underlying OS. 此体系结构有助于提高性能,因为JMV不必再从底层操作系统请求相同的内存。 It will still be within the range you define in -Xmx JVM parameter. 它仍然在您在-Xmx JVM参数中定义的范围内。

See this IBM link for some interesting details. 有关一些有趣的细节,请参阅此IBM链接。 http://www-01.ibm.com/support/docview.wss?uid=swg21326774 http://www-01.ibm.com/support/docview.wss?uid=swg21326774

Unfortunately this is one of the grey areas of JVM; 不幸的是,这是JVM的一个灰色区域; you really don't have much of a control on how OS and JVM share memory between each other. 你真的没有太多关于OS和JVM如何在彼此之间共享内存的控制。 Think of JVM as a Virtual OS that requires some memory to run. 将JVM视为需要运行某些内存的虚拟操作系统。 Both your parent OS and the VM are hungry for resources and want to hang on to the acquired resources the as much memory as possible. 您的父操作系统和虚拟机都渴望获得资源,并且希望尽可能多地将所获得的资源挂在所获取的资源上。 Requesting for more memory from OS is a time consuming operation so most of the JVMs do not release the memory back to the OS even when they don't need it anymore. 从操作系统请求更多内存是一项耗时的操作,因此大多数JVM都不会将内存释放回操作系统,即使它们不再需要它也是如此。

See this white paper from Oracle for more details on internal JVM memory management. 有关内部JVM内存管理的更多详细信息,请参阅Oracle的此白皮书。 http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf http://www.oracle.com/technetwork/java/javase/memorymanagement-whitepaper-150215.pdf

I would suggest you to read the IBM link first and then you can delve into the weird world of memory explained in the white paper. 我建议你先阅读IBM链接,然后你可以深入研究白皮书中解释的奇怪的内存世界。 Both of these links are very informative and interesting. 这两个链接都非常丰富和有趣。

OS footprint of java process are composed from Java进程的OS足迹由

  • java heap (it's size in limited by -Xmx ) java堆(它的大小受-Xmx限制)
  • java classes related metadata (or permanent generation in HotSpot JVM) java类相关元数据(或HotSpot JVM中的永久生成)
  • non-heap memory accessible via NIO 通过NIO可访问的非堆内存
  • stack space for java threads 用于java线程的堆栈空间

Some garbage collection algorithms are returning free memory back to OS, other do not. 一些垃圾收集算法将可用内存返回给OS,其他则没有。 In HotSpot JVM, serial old space collector (usually enabled by default) are returning memory back to OS (so you can see shrinking of process). 在HotSpot JVM中,串行旧空间收集器(通常默认启用)将内存返回到OS(因此您可以看到进程收缩)。 Though, other collector such as -XX:+UseParallelOldGC or -XX:+UseConcMarkSweepGC will never return unused heap memory to OS. 但是,其他收集器如-XX:+UseParallelOldGC-XX:+UseConcMarkSweepGC将永远不会将未使用的堆内存返回给OS。

HotSpot JVM has options to manage / limit all memory areas mentioned above, you can find comprehensive list of JVM options related to memory sizing and GC tuning in my blog . HotSpot JVM具有管理/限制上述所有内存区域的选项,您可以在我的博客中找到与内存大小调整和GC调整相关的JVM选项的完整列表。

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

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