I am looking for an easy way to find out how much memory the JVM on my computer has allocated to a specific process, i have tried using VisualVM, but it cannot find the process.
I should mention that this it's running a Windows Service, not a regular process.
Any suggestions ?
Thank in advance.
Types of Memory Areas Allocated By the JVM: The class method area is the memory block that stores the class code, variable code(static variable, runtime constant), method code, and the constructor of a Java program. (Here method means the function which is written inside the class).
Using VisualVM (jvisualvm) It allows you to trace a running Java program and see its the memory and CPU consumption. You can also use it to create a memory heap dump to analyze the objects in the heap. https://visualvm.github.io/ [Visualvm] is part of the jdk distribution (as of Update 7 for jdk1. 6).
Note that the JVM uses more memory than just the heap. For example Java methods, thread stacks and native handles are allocated in memory separate from the heap, as well as JVM internal data structures. The heap is sometimes divided into two areas (or generations) called the nursery (or young space) and the old space.
there is a command that comes with the JRE called jps
which you can use to see all the running java processes. using jps
with -v
gives you the launch parameters of each process.
You can see here the launch parameters which will tell you the memory usage of each process.
This command should run also on Windows, just replace the terminal with a command prompt.
I use in android (if you want to know a programatic way):
// get the total memory for my app
long total = Runtime.getRuntime().totalMemory();
// get the free memory available
long free = Runtime.getRuntime().freeMemory();
// some simple arithmetic to see how much i use
long used = total - free;
System.out.println("Used memory in bytes: " + used);
Works for the PC too(just tested)!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With