From 04e6c68242db78200aa5d96315e5d7bffb2f9155 Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Fri, 24 Jan 2014 00:14:58 +0000 Subject: Properly dispose of drawing objects to reduce/stop memory leakage on generating map tiles with the MapImageModule and TexturedMapTileRenderer (the current defaults) --- .../CoreModules/World/WorldMap/WorldMapModule.cs | 91 ++++++++++++---------- 1 file changed, 49 insertions(+), 42 deletions(-) (limited to 'OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs') diff --git a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs index 8df9623..ddaf9fb 100644 --- a/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs +++ b/OpenSim/Region/CoreModules/World/WorldMap/WorldMapModule.cs @@ -1501,62 +1501,69 @@ namespace OpenSim.Region.CoreModules.World.WorldMap private Byte[] GenerateOverlay() { - Bitmap overlay = new Bitmap(256, 256); - - bool[,] saleBitmap = new bool[64, 64]; - for (int x = 0 ; x < 64 ; x++) + using (Bitmap overlay = new Bitmap(256, 256)) { - for (int y = 0 ; y < 64 ; y++) - saleBitmap[x, y] = false; - } - - bool landForSale = false; + bool[,] saleBitmap = new bool[64, 64]; + for (int x = 0 ; x < 64 ; x++) + { + for (int y = 0 ; y < 64 ; y++) + saleBitmap[x, y] = false; + } - List parcels = m_scene.LandChannel.AllParcels(); + bool landForSale = false; - Color background = Color.FromArgb(0, 0, 0, 0); - SolidBrush transparent = new SolidBrush(background); - Graphics g = Graphics.FromImage(overlay); - g.FillRectangle(transparent, 0, 0, 256, 256); + List parcels = m_scene.LandChannel.AllParcels(); - SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9)); + Color background = Color.FromArgb(0, 0, 0, 0); - foreach (ILandObject land in parcels) - { - // m_log.DebugFormat("[WORLD MAP]: Parcel {0} flags {1}", land.LandData.Name, land.LandData.Flags); - if ((land.LandData.Flags & (uint)ParcelFlags.ForSale) != 0) + using (Graphics g = Graphics.FromImage(overlay)) { - landForSale = true; + using (SolidBrush transparent = new SolidBrush(background)) + g.FillRectangle(transparent, 0, 0, 256, 256); - saleBitmap = land.MergeLandBitmaps(saleBitmap, land.GetLandBitmap()); - } - } - if (!landForSale) - { - m_log.DebugFormat("[WORLD MAP]: Region {0} has no parcels for sale, not generating overlay", m_scene.RegionInfo.RegionName); - return null; - } + foreach (ILandObject land in parcels) + { + // m_log.DebugFormat("[WORLD MAP]: Parcel {0} flags {1}", land.LandData.Name, land.LandData.Flags); + if ((land.LandData.Flags & (uint)ParcelFlags.ForSale) != 0) + { + landForSale = true; - m_log.DebugFormat("[WORLD MAP]: Region {0} has parcels for sale, generating overlay", m_scene.RegionInfo.RegionName); + saleBitmap = land.MergeLandBitmaps(saleBitmap, land.GetLandBitmap()); + } + } - for (int x = 0 ; x < 64 ; x++) - { - for (int y = 0 ; y < 64 ; y++) + if (!landForSale) + { + m_log.DebugFormat("[WORLD MAP]: Region {0} has no parcels for sale, not generating overlay", m_scene.RegionInfo.RegionName); + return null; + } + + m_log.DebugFormat("[WORLD MAP]: Region {0} has parcels for sale, generating overlay", m_scene.RegionInfo.RegionName); + + using (SolidBrush yellow = new SolidBrush(Color.FromArgb(255, 249, 223, 9))) + { + for (int x = 0 ; x < 64 ; x++) + { + for (int y = 0 ; y < 64 ; y++) + { + if (saleBitmap[x, y]) + g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4); + } + } + } + } + + try + { + return OpenJPEG.EncodeFromImage(overlay, true); + } + catch (Exception e) { - if (saleBitmap[x, y]) - g.FillRectangle(yellow, x * 4, 252 - (y * 4), 4, 4); + m_log.DebugFormat("[WORLD MAP]: Error creating parcel overlay: " + e.ToString()); } } - try - { - return OpenJPEG.EncodeFromImage(overlay, true); - } - catch (Exception e) - { - m_log.DebugFormat("[WORLD MAP]: Error creating parcel overlay: " + e.ToString()); - } return null; } } -- cgit v1.1