changeset 36:10e60b05c7ec

Fix memory leak each time a check was executed.
author Brad Greco <brad@bgreco.net>
date Sun, 15 Sep 2019 20:48:55 -0400
parents 2ffb0bda7705
children 547181b2b418
files ServerMonitor.sln ServerMonitor/Objects/ServerMonitor.cs ServerMonitor/Properties/AssemblyInfo.cs ServerMonitor/ServerMonitor.csproj
diffstat 4 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/ServerMonitor.sln	Sat Jul 13 12:18:21 2019 -0400
+++ b/ServerMonitor.sln	Sun Sep 15 20:48:55 2019 -0400
@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.27703.2035
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29306.81
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerMonitor", "ServerMonitor\ServerMonitor.csproj", "{68E905D9-18FD-4ADC-9CF7-B5984C3E2158}"
 EndProject
@@ -28,4 +28,7 @@
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {E5AB43B5-6016-4C4B-A846-4AC2A3DFEE62}
 	EndGlobalSection
+	GlobalSection(Performance) = preSolution
+		HasPerformanceSessions = true
+	EndGlobalSection
 EndGlobal
--- a/ServerMonitor/Objects/ServerMonitor.cs	Sat Jul 13 12:18:21 2019 -0400
+++ b/ServerMonitor/Objects/ServerMonitor.cs	Sun Sep 15 20:48:55 2019 -0400
@@ -35,6 +35,8 @@
         // A check task begins by sleeping until the next scheduled execution time,
         // then executes.
         private Dictionary<Task<CheckResult>, int> tasks;
+        // XML serializer that can handle servers and all check types.
+        private XmlSerializer xmlSerializer;
         private ServerSummaryForm mainForm;
         private WaveOut waveOut = new WaveOut();
         MediaFoundationReader mediaReader;
@@ -63,6 +65,7 @@
             configFileDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ServerMonitor");
             ConfigFile = Path.Combine(configFileDir, "servers.xml");
             logger = new Logger(Path.Combine(configFileDir, "monitor.log"));
+            xmlSerializer = new XmlSerializer(typeof(List<Server>), Check.CheckTypes);
         }
 
         /// <summary>Registers a new server with the server monitor.</summary>
@@ -99,9 +102,8 @@
             try
             {
                 reader = new StreamReader(ConfigFile);
-                XmlSerializer serializer = CreateXmlSerializer();
                 Servers.Clear();
-                Servers.AddRange((List<Server>)serializer.Deserialize(reader));
+                Servers.AddRange((List<Server>)xmlSerializer.Deserialize(reader));
                 // Do some more set-up now that the servers and checks have been loaded.
                 foreach (Server server in Servers)
                 {
@@ -169,7 +171,6 @@
         {
             GenerateIds();
             TextWriter writer = null;
-            XmlSerializer serializer = null;
             try
             {
                 // Make a backup first in case something goes wrong in the middle of writing.
@@ -179,16 +180,14 @@
             try
             {
                 writer = new StreamWriter(ConfigFile);
-                serializer = CreateXmlSerializer();
-                serializer.Serialize(writer, Servers);
+                xmlSerializer.Serialize(writer, Servers);
             }
             catch (DirectoryNotFoundException)
             {
                 // If the directory does not exist, create it and try again.
                 Directory.CreateDirectory(configFileDir);
                 writer = new StreamWriter(ConfigFile);
-                serializer = CreateXmlSerializer();
-                serializer.Serialize(writer, Servers);
+                xmlSerializer.Serialize(writer, Servers);
             }
             finally
             {
--- a/ServerMonitor/Properties/AssemblyInfo.cs	Sat Jul 13 12:18:21 2019 -0400
+++ b/ServerMonitor/Properties/AssemblyInfo.cs	Sun Sep 15 20:48:55 2019 -0400
@@ -32,5 +32,5 @@
 // You can specify all the values or you can default the Build and Revision Numbers
 // by using the '*' as shown below:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
--- a/ServerMonitor/ServerMonitor.csproj	Sat Jul 13 12:18:21 2019 -0400
+++ b/ServerMonitor/ServerMonitor.csproj	Sun Sep 15 20:48:55 2019 -0400
@@ -31,7 +31,7 @@
     <ProductName>Server Monitor</ProductName>
     <PublisherName>Brad Greco</PublisherName>
     <ApplicationRevision>0</ApplicationRevision>
-    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
+    <ApplicationVersion>1.1.0.%2a</ApplicationVersion>
     <UseApplicationTrust>false</UseApplicationTrust>
     <BootstrapperEnabled>true</BootstrapperEnabled>
   </PropertyGroup>