使用StreamReader和XmlSeriizer的内存泄漏
while (true){ try { foreach (string sym in stringlist) { StreamReader r = new StreamReader(@"C:\Program Files\" + sym + ".xml"); XmlSerializer xml = new XmlSerializer(typeof(XMLObj), new XmlRootAttribute("rootNode")); XMLObj obj = (XMLObj)xml.Deserialize(r); obj.Dispose(); r.Dispose(); r.Close(); } } catch(Exception ex) { Console.WriteLine(ex.ToString()); } Thread.Sleep(1000); Console.Clear(); }
[Serializable()]public class XMLObj: IDisposable{ [XmlElement("block")] public List<XMLnode> nodes{ get; set; } public XMLObj() { } public void Dispose() { nodes.ForEach(n => n.Dispose()); nodes= null; GC.SuppressFinalize(this); }}
慕标5832272
慕尼黑5688855