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]
-
mv*@spam.guard.caspershouse.com
"Arne Vajhøj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
em*************@gmail.com wrote:
>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