Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Leak with XmlDocument()
    primarykey
    data
    text
    <p>I believe I have memory leak with some of my code that uses the XmlDocument class.</p> <p>My program runs on a Windows 6.1.4 device (C#) and reads from a database on another server to see if any programs installed on the device need to be uninstalled and then reads from an XmlDocument to get the names of the programs that are uninstallable. The program then matches the lists and uninstalls accordingly, if necessary. This process is looped infinitely and runs in the background but what I'm noticing is that the memory creeps up slowly over time and the program eventually catches an <code>OutOfMemoryException</code>. </p> <p>If I comment out everything and do nothing in the loop, the memory stays right around 2MB consistantly. If I leave everything but the following code commented out then the memory usage goes up .05 megabytes every minute or so continuously. Those results are with having the loop sleep for 1 second. The regular sleep speed is about 10 minutes. Any thoughts as to what could be causing the leak and if it has anything to do with the XmlDocument class?</p> <pre><code>foreach (string programName in uninstallPrograms) { XmlDocument xmlDoc1 = new XmlDocument(); xmlDoc1.LoadXml("&lt;wap-provisioningdoc&gt;" + " &lt;characteristic type=\"UnInstall\"&gt;" + " &lt;characteristic type=\"" + programName + "\"&gt;" + " &lt;parm name=\"uninstall\" value=\"1\"/&gt;" + " &lt;/characteristic&gt;" + " &lt;/characteristic&gt;" + "&lt;/wap-provisioningdoc&gt;"); xmlDoc1 = ConfigurationManager.ProcessConfiguration(xmlDoc1, true); cmdStr += "DELETE FROM DEVICE_APPS WHERE ID = " + deviceAppIDList[count++] + "; "; xmlDoc1 = null; } // Check for pre-installed apps to uninstall count = 0; XmlDocument xmlDoc2 = new XmlDocument(); xmlDoc2.LoadXml("&lt;wap-provisioningdoc&gt;&lt;characteristic-query type=\"UnInstall\"/&gt;" + "&lt;/wap-provisioningdoc&gt;"); /**** The line below seems to be the cause of the memory leak ****/ //xmlDoc2 = ConfigurationManager.ProcessConfiguration(xmlDoc2, true); XmlNodeList xmlNodeList = xmlDoc2.SelectNodes("wap-provisioningdoc/" + "characteristic[@type='UnInstall']/characteristic/@type"); xmlDoc2 = null; </code></pre> <p><code>cmdStr</code> does eventually get used and is set to <code>string.Empty</code> at the end of the loop. At first I had didn't have <code>xmlDoc = null;</code> in my code but it didn't help either way. I've tried adding <code>GC.Collect();</code> at the end of my loop and that seemed to help slow down the leak but it doesn't fix it entirely. Plus I've read it's not good practice to use it anyway.</p> <p><strong>Edit:</strong> So it seems to be the ConfigurationManager line that I commented out in my code above that has the memory leak. As soon as I comment out that line of code the memory leak stops. It starts back up when I uncomment this line. Is there something I need to do after making the call to ProcessConfiguration to release the memory?</p> <p>Also, I am using the Microsoft.WindowsMobile.Configuration namespace for ConfigurationManager runtime version 1.1.4322 since System.Configuration does not exist in CF.</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