From a41cd1d0695c01e4096fa0b7696b415a4c7455fc Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 23 Oct 2009 13:14:29 -0700 Subject: * Unregister Mono.Addins event handlers in PluginLoader.Dispose() and always handle PluginLoader with the using pattern. This freed up 121,634,796 bytes on my system * Avoid allocating an Action object every round of the OutgoingPacketHandler * Removed unnecessary semi-colon endings from OpenSim.ini.example [InterestManagement] section --- OpenSim/Data/DataPluginFactory.cs | 15 ++++++++------- OpenSim/Framework/PluginLoader.cs | 9 +++++++-- OpenSim/Grid/GridServer/GridServerBase.cs | 10 +++++----- OpenSim/Region/Application/OpenSimBase.cs | 10 +++++----- OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs | 6 +++++- OpenSim/Region/Framework/Scenes/Scene.cs | 13 +++++++++---- 6 files changed, 39 insertions(+), 24 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Data/DataPluginFactory.cs b/OpenSim/Data/DataPluginFactory.cs index 718c6b2..841f71e 100644 --- a/OpenSim/Data/DataPluginFactory.cs +++ b/OpenSim/Data/DataPluginFactory.cs @@ -119,14 +119,15 @@ namespace OpenSim.Data PluginLoaderParamFactory(connect, out pluginInitialiser, out extensionPointPath); - PluginLoader loader = new PluginLoader(pluginInitialiser); - - // loader will try to load all providers (MySQL, MSSQL, etc) - // unless it is constrainted to the correct "Provider" entry in the addin.xml - loader.Add(extensionPointPath, new PluginProviderFilter(provider)); - loader.Load(); + using (PluginLoader loader = new PluginLoader(pluginInitialiser)) + { + // loader will try to load all providers (MySQL, MSSQL, etc) + // unless it is constrainted to the correct "Provider" entry in the addin.xml + loader.Add(extensionPointPath, new PluginProviderFilter(provider)); + loader.Load(); - return loader.Plugins; + return loader.Plugins; + } } /// diff --git a/OpenSim/Framework/PluginLoader.cs b/OpenSim/Framework/PluginLoader.cs index 5d38f5f..819cb7b 100644 --- a/OpenSim/Framework/PluginLoader.cs +++ b/OpenSim/Framework/PluginLoader.cs @@ -194,10 +194,15 @@ namespace OpenSim.Framework } } + /// + /// Unregisters Mono.Addins event handlers, allowing temporary Mono.Addins + /// data to be garbage collected. Since the plugins created by this loader + /// are meant to outlive the loader itself, they must be disposed separately + /// public void Dispose() { - foreach (T plugin in Plugins) - plugin.Dispose(); + AddinManager.AddinLoadError -= on_addinloaderror_; + AddinManager.AddinLoaded -= on_addinloaded_; } private void initialise_plugin_dir_(string dir) diff --git a/OpenSim/Grid/GridServer/GridServerBase.cs b/OpenSim/Grid/GridServer/GridServerBase.cs index d63ac2e..113d5c8 100644 --- a/OpenSim/Grid/GridServer/GridServerBase.cs +++ b/OpenSim/Grid/GridServer/GridServerBase.cs @@ -115,11 +115,11 @@ namespace OpenSim.Grid.GridServer protected virtual void LoadPlugins() { - PluginLoader loader = - new PluginLoader(new GridPluginInitialiser(this)); - - loader.Load("/OpenSim/GridServer"); - m_plugins = loader.Plugins; + using (PluginLoader loader = new PluginLoader(new GridPluginInitialiser(this))) + { + loader.Load("/OpenSim/GridServer"); + m_plugins = loader.Plugins; + } } public override void ShutdownSpecific() diff --git a/OpenSim/Region/Application/OpenSimBase.cs b/OpenSim/Region/Application/OpenSimBase.cs index 3df3a1c..cc18f1a 100644 --- a/OpenSim/Region/Application/OpenSimBase.cs +++ b/OpenSim/Region/Application/OpenSimBase.cs @@ -162,11 +162,11 @@ namespace OpenSim protected virtual void LoadPlugins() { - PluginLoader loader = - new PluginLoader(new ApplicationPluginInitialiser(this)); - - loader.Load("/OpenSim/Startup"); - m_plugins = loader.Plugins; + using (PluginLoader loader = new PluginLoader(new ApplicationPluginInitialiser(this))) + { + loader.Load("/OpenSim/Startup"); + m_plugins = loader.Plugins; + } } protected override List GetHelpTopics() diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs index 232c9c9..1dd58bf 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLUDPServer.cs @@ -814,6 +814,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP // on to en-US to avoid number parsing issues Culture.SetCurrentCulture(); + // Typecast the function to an Action once here to avoid allocating a new + // Action generic every round + Action clientPacketHandler = ClientOutgoingPacketHandler; + while (base.IsRunning) { try @@ -862,7 +866,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP // Handle outgoing packets, resends, acknowledgements, and pings for each // client. m_packetSent will be set to true if a packet is sent - m_scene.ClientManager.ForEachSync(ClientOutgoingPacketHandler); + m_scene.ClientManager.ForEachSync(clientPacketHandler); // If nothing was sent, sleep for the minimum amount of time before a // token bucket could get more tokens diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index ee848bb..a3bc04b 100644 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -1223,10 +1223,7 @@ namespace OpenSim.Region.Framework.Scenes if (!m_backingup) { m_backingup = true; - - System.ComponentModel.BackgroundWorker backupWorker = new System.ComponentModel.BackgroundWorker(); - backupWorker.DoWork += delegate(object sender, System.ComponentModel.DoWorkEventArgs e) { Backup(); }; - backupWorker.RunWorkerAsync(); + Util.FireAndForget(BackupWaitCallback); } } @@ -1239,6 +1236,14 @@ namespace OpenSim.Region.Framework.Scenes } /// + /// Wrapper for Backup() that can be called with Util.FireAndForget() + /// + private void BackupWaitCallback(object o) + { + Backup(); + } + + /// /// Backup the scene. This acts as the main method of the backup thread. /// /// -- cgit v1.1