Search code examples
javaspringmemory-managementprototypejavabeans

A way to track the situation with memory during creation and destruction of Prototype-beans in Spring application?


In a part of our project we have some number of prototype-beans. I would like to have a clear understanding of what is going on during execution of that part.

Is there any way to track the situation during creation of prototype-beans, what amount of memory they start using, and to track whether these beans were destroyed successfully?

I need not only printing the information in the console, but I would like to see actual situation with memory or the list of existing in memory prototype-beans.


Solution

  • I have found a way to see the actual picture about created prototype-beans. I use free VisualVM memory profiler.

    In the Sampler tab you can see all instances of created classes including singleton and prototype beans.

    You'll see the names of your own packages and classes. In this case:

    • prototype is a package with my prototype-beans.

    • singleton is a package with my singleton-beans.

    • newclasses is a package with classes that I created by new operator.

    Also after the garbage collector will clean the memory you will see the result here.

    enter image description here