Heap Memory of a Windows Process

E

emer.kurbegovic

how can i get heap memory of a windows process with C#? For example, I
would like to see the value of the heap memory allocated for my
"java.exe" process.

thanks in advance.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

how can i get heap memory of a windows process with C#? For example, I
would like to see the value of the heap memory allocated for my
"java.exe" process.

It is probably impossible to get a true mesaurement if Java heap,
becaus ethat is "java internals", but some quick experimentation
showed that:

Process[] p = Process.GetProcessesByName("java");
Console.WriteLine(p[0].WorkingSet64);

produced a decent approximation on my system.

I will not guarantee that it will on your system, but you
could try it.

Arne
 
N

Nicholas Paldino [.NET/C# MVP]

I dobut that this would always be a good approximation. You are getting
the working set, which is by no means an accurate representation of heap
size.

If you want to get the statistics for the heap, you have to get the
runtime from within the app through a call to the static getRuntime method
on the Runtime class, and then access the various methods which detail the
runtime at that particular point (totalMemory, maxMemory, freeMemory
methods).

Those values would have to be pushed out of the process (in a manner
that can be read by your process). A file is the first thing that comes to
mind.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Arne Vajhøj said:
how can i get heap memory of a windows process with C#? For example, I
would like to see the value of the heap memory allocated for my
"java.exe" process.

It is probably impossible to get a true mesaurement if Java heap,
becaus ethat is "java internals", but some quick experimentation
showed that:

Process[] p = Process.GetProcessesByName("java");
Console.WriteLine(p[0].WorkingSet64);

produced a decent approximation on my system.

I will not guarantee that it will on your system, but you
could try it.

Arne
 
N

Nicholas Paldino [.NET/C# MVP]

Additionally, java provides tools which will allow monitoring of the
JVM:

http://java.sun.com/performance/jvmstat/


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Arne Vajhøj said:
how can i get heap memory of a windows process with C#? For example, I
would like to see the value of the heap memory allocated for my
"java.exe" process.

It is probably impossible to get a true mesaurement if Java heap,
becaus ethat is "java internals", but some quick experimentation
showed that:

Process[] p = Process.GetProcessesByName("java");
Console.WriteLine(p[0].WorkingSet64);

produced a decent approximation on my system.

I will not guarantee that it will on your system, but you
could try it.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top