Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the memory allocated by the JVM

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.

like image 982
David Faizulaev Avatar asked Jul 16 '13 12:07

David Faizulaev


People also ask

Where is the memory allocated for the JVM?

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).

How do I check my JVM memory usage?

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).

What is JVM memory allocation?

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.


2 Answers

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.

terminal

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.

like image 145
Bryan Abrams Avatar answered Oct 15 '22 21:10

Bryan Abrams


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)!

like image 6
john Avatar answered Oct 15 '22 19:10

john