为什么堆内存使用量和加载类的数量不断增加? [英] Why do heap memory usage and number of loaded classes keep increasing?

查看:348
本文介绍了为什么堆内存使用量和加载类的数量不断增加?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 JVM Explorer -






在完成垃圾收集程序后向应用程序发送一些请求后 - 放大图片



解决方案


为什么'使用堆内存'保持不变即使在应用程序启动后还没有收到任何请求,它会增加吗? (图1)


JVM中的某些东西正在创建对象。你需要一个内存分析器来看看这是做什么的。它可能是Swing,或yoru应用程序或其他库的一部分。



BTW大多数分析工具使用JMX处理大量垃圾。例如当我在我的一些应用程序上运行FlightRecorder或VisualVM时,它显示JMX监视正在创建大部分垃圾。


为什么即使在垃圾收集之后在收到任何请求之前'使用过的堆内存'不断增加? (图2)


无论创建对象是什么,仍在创建对象。


为什么垃圾收集后,通过向应用程序发送一些请求,加载类的数量正在增加?


延迟加载类。在你做某事之前不需要一些类。


应用程序是不是应该使用以前的类?


是的,但这并不意味着它不需要更多的课程。


为什么它只增加几乎所有东西(堆,加载类的数量)? (图3)


您的申请正在做更多的工作。



如果你我不想知道应用程序正在做什么工作,我建议使用像VisualVM或Flight Recorder这样的内存分析器。我使用YourKit来解决这些问题。



注意:调整Java程序需要付出艰苦的努力,这样才不会产生垃圾,我会说只有大多数库如果它导致已知的性能问题,请尝试减少垃圾。


I am using JVM Explorer - link to JVM Explorer , to profile my Spring application. I have following questions about it.

  • Why 'Used Heap Memory' keeps increasing even after the application has started up and have not received any requests yet? (Image 1)

  • Why even after garbage collection and before receiving any requests 'Used Heap Memory' keeps increasing? (Image2)

  • Why after garbage collection, by sending some requests to the application number of loaded classes is increasing? Is not the application supposed to use previous classes? why is it just increasing almost everything (heap, number of loaded classes)? (Image3)

    After application starts up - enlarge image

    After clicking on 'Run Garbage Collector' button. - enlarge image

After sending some requests to the application following completion of Garbage Collection Procedure - enlarge image

解决方案

Why 'Used Heap Memory' keeps increasing even after the application has started up and have not received any requests yet? (Image 1)

Something in your JVM is creating objects. You would need a memory profiler to see what is doing this. It could be part of Swing, or yoru application or another library.

BTW Most profiling tools use JMX which processes a lot of garbage. e.g. when I run FlightRecorder or VisualVM on some of my applications it shows the JMX monitoring is creating most of the garbage.

Why even after garbage collection and before receiving any requests 'Used Heap Memory' keeps increasing? (Image2)

Whatever was creating objects is still creating objects.

Why after garbage collection, by sending some requests to the application number of loaded classes is increasing?

Classes are lazily loaded. Some classes are not needed until you do something.

Is not the application supposed to use previous classes?

Yes, but this doesn't mean it won't need more classes.

why is it just increasing almost everything (heap, number of loaded classes)? (Image3)

Your application is doing more work.

If you wan't to know what work the application is doing, I suggest using a memory profiler like VisualVM or Flight Recorder. I use YourKit for these sort of questions.

Note: it takes hard work to tune a Java program so that it doesn't produce garbage and I would say most libraries only try to reduce garbage if it causes a known performance problem.

这篇关于为什么堆内存使用量和加载类的数量不断增加?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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