# HG changeset patch # User Brad Greco # Date 1568594935 14400 # Node ID 10e60b05c7ec1689b6fa91d7224721dae95ac22d # Parent 2ffb0bda77050d9c1a8e4c5fc289c8742ae9fff2 Fix memory leak each time a check was executed. diff -r 2ffb0bda7705 -r 10e60b05c7ec ServerMonitor.sln --- 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 diff -r 2ffb0bda7705 -r 10e60b05c7ec ServerMonitor/Objects/ServerMonitor.cs --- 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, 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), Check.CheckTypes); } /// Registers a new server with the server monitor. @@ -99,9 +102,8 @@ try { reader = new StreamReader(ConfigFile); - XmlSerializer serializer = CreateXmlSerializer(); Servers.Clear(); - Servers.AddRange((List)serializer.Deserialize(reader)); + Servers.AddRange((List)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 { diff -r 2ffb0bda7705 -r 10e60b05c7ec ServerMonitor/Properties/AssemblyInfo.cs --- 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")] diff -r 2ffb0bda7705 -r 10e60b05c7ec ServerMonitor/ServerMonitor.csproj --- 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 @@ Server Monitor Brad Greco 0 - 1.0.0.%2a + 1.1.0.%2a false true