Note that there are some explanatory texts on larger screens.

plurals
  1. POWMI causing memory leak(when run in multiple threads)
    primarykey
    data
    text
    <p>My question is similar to <a href="https://stackoverflow.com/questions/5934639/periodical-wmi-query-causes-memory-leak">Periodical WMI Query Causes Memory Leak?</a> but with threads.</p> <p>I am writing a simple application to monitor process and memory information from a number of servers. However there is a memory leak. I have whittled down the problem to the following simple Console application.</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Management; using System.Threading; namespace ConsoleApplication1 { class Program { public static void dummyQuery(string ip, string query) { ConnectionOptions connOptions = new ConnectionOptions(); ManagementScope mgtScope = new ManagementScope(@"\\" + ip + @"\ROOT\CIMV2", connOptions); mgtScope.Connect(); ObjectQuery queryo = new ObjectQuery(query); using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(mgtScope, queryo)) { using (ManagementObjectCollection moc = searcher.Get()) { } } } static void Main(string[] args) { Console.ReadKey(); int times = 10000; for (int i = 0; i &lt; times; i++) { Thread t = new Thread(o =&gt; dummyQuery("xxxxxxxxx", @"SELECT WorkingSetSize FROM Win32_Process WHERE name='W3WP.exe'")); //t.IsBackground = true; t.Start(); System.Threading.Thread.Sleep(50); } Console.ReadKey(); //GC.Collect(); Console.ReadKey(); } } } </code></pre> <p>Is there a way to run WMI queries from threads safely?</p> <p>This is extracted from a much more complicated wpf application that checks the status of many servers much like the dummyQuery method. That application leaks memory at a disturbingly fast rate related to WMI calls. This sample looks like it is not leaking memory (Jim Mischel had a better way of checking this). I will install a profiler and take another look at the original app.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload