How can i get .NET CLR Memory heap size from another process?
<p><strong>Background</strong></p>

<p>We have automated tests using Telerik TestStudio, (visual studio plugin).
This connects to our WPF application an executes the tests, so the automation runs as one process and our application the other.
Now i want to measure and secure so that we don't have any memory leaks or simular, we want to see this as early as possible during the development, before it reaches the customers.</p>

<p>To measure the Memory is no problem. But the .NET CLR Memory Heap size seems to more tricky.</p>

<p>It's the same result as the Windows Performance Monitor can get that i'm after. (perfmon.exe)
<img src="http://i.stack.imgur.com/aLOyN.png" alt="perfmon.exe"></p>

<p><strong>What i've tried</strong></p>

<p>The garbage collector contains this information for my process, so i can't use this</p>

<pre><code>var heap = GC.GetTotalMemory();
</code></pre>

<p>What i have tried is to use the <a href="http://msdn.microsoft.com/en-us/library/aa394554%28v=vs.85%29.aspx" rel="nofollow">WMI</a> classes to get this but without succeding.. 
There is one class that is intressting : Win32_PerfFormattedData_NETFramework_NETCLRMemory
So i thought that i would give it a try..</p>

<pre><code>var searcher = new ManagementObjectSearcher(@"select * from Win32_PerfFormattedData_NETFramework_NETCLRMemory");
foreach (ManagementBaseObject baseObject in searcher.Get())
{
    var heap0 = baseObject["HeapSize0"];
    var heap1 = baseObject["HeapSize1"];
    var heap2 = baseObject["HeapSize2"];
}
</code></pre>

<p>Problem above is that the Get() dosn't return anything at all, if i put the breakpoint at the first line in the foreach loop it will not enter.</p>

<p><strong>Questions</strong></p>

<ul>
<li>Is there any other way in doing this in C#? </li>
<li>Have anyone tried to get this Heap size from another process before?</li>
</ul>
