There are instances where you would want to check memory allocation for your application in cases where your application sometimes randomly crashes. This is usually due to memory leaks in the application.
Once you install JDK in your machine it comes with visualvm. It is just a matter connecting to it.
1.) Make sure application server is running
2.) go to visualvm:
3.) You will see a pop-up window, under remote, key-in: localhost:8080 (or whatever port you are in)
4.) Successfully logged in you will see, on the upper right you can perform a heap dump (current state of memory allocation and you will see which class are taking the most memory). On this dashboard you can monitor how the application is handling memory, threads, and Garbage Collection.
4.) Once you click heap dump you will be redirected to this page, at which point you can find the biggest objects in your application:
5.) you can also see in the classes tab which specific classes are eating up the memory