Possible Memory leak in Number of Loaded classes in Java Application

前端 未结 6 506
被撕碎了的回忆
被撕碎了的回忆 2021-02-02 02:29

I recently began profiling an osgi java application that I am writing using VisualVM. One thing I have noticed is that when the application starts sending data to a client (ove

6条回答
  •  时光说笑
    2021-02-02 03:24

    Unless I misunderstand, we're looking here at loaded classes, not instances.

    When your code first references a class, the JVM has the ClassLoader go out and fetch the information about the class from a .class file or the like.

    I'm not sure under what conditions it would unload a class. Certainly it should never unload any class with static information.

    So I would expect a pattern roughly like yours, where as your application runs it goes into areas and references new classes, so the number of loaded classes would go up and up.

    However, two things seems strange to me:

    1. Why is it so linear?
    2. Why doesn't it plateau?

    I would expect it to trend upwards, but in a wobbly line, and then taper off on the increase as the JVM has already loaded most of the classes your program references. I mean, there are a finite number of classes referenced in most applications.

    Are you dynamically creating new classes on the fly somehow?

    I would suggest running a simpler test app through the same debugger to get a baseline case. Then you could consider implementing your own ClassLoader that spits out some debug information, or maybe there is a tool to make it report.

    You need to figure out what these classes being loaded are.

提交回复
热议问题