workaround potencial memory leak

LSLKeyTest
UbitUmarov 2016-08-22 05:47:19 +01:00
parent 222a5b655f
commit 52a80f1742
4 changed files with 47 additions and 37 deletions

View File

@ -354,9 +354,9 @@ namespace OpenSim.Capabilities.Handlers
byte[] data = new byte[0];
MemoryStream imgstream = new MemoryStream();
Bitmap mTexture = new Bitmap(1, 1);
ManagedImage managedImage;
Image image = (Image)mTexture;
Bitmap mTexture = null;
ManagedImage managedImage = null;
Image image = null;
try
{
@ -365,12 +365,13 @@ namespace OpenSim.Capabilities.Handlers
imgstream = new MemoryStream();
// Decode image to System.Drawing.Image
if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image))
if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image) && image != null)
{
// Save to bitmap
mTexture = new Bitmap(image);
EncoderParameters myEncoderParameters = new EncoderParameters();
using(EncoderParameters myEncoderParameters = new EncoderParameters())
{
myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,95L);
// Save bitmap to stream
@ -383,7 +384,7 @@ namespace OpenSim.Capabilities.Handlers
}
else
m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
}
}
}
catch (Exception e)
@ -400,6 +401,8 @@ namespace OpenSim.Capabilities.Handlers
if (image != null)
image.Dispose();
if(managedImage != null)
managedImage.Clear();
if (imgstream != null)
{
imgstream.Close();

View File

@ -359,9 +359,9 @@ namespace OpenSim.Capabilities.Handlers
byte[] data = new byte[0];
MemoryStream imgstream = new MemoryStream();
Bitmap mTexture = new Bitmap(1, 1);
ManagedImage managedImage;
Image image = (Image)mTexture;
Bitmap mTexture = null;
ManagedImage managedImage = null;
Image image = null;
try
{
@ -370,12 +370,13 @@ namespace OpenSim.Capabilities.Handlers
imgstream = new MemoryStream();
// Decode image to System.Drawing.Image
if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image))
if (OpenJPEG.DecodeToImage(texture.Data, out managedImage, out image) && image != null)
{
// Save to bitmap
mTexture = new Bitmap(image);
EncoderParameters myEncoderParameters = new EncoderParameters();
using(EncoderParameters myEncoderParameters = new EncoderParameters())
{
myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,95L);
// Save bitmap to stream
@ -388,7 +389,7 @@ namespace OpenSim.Capabilities.Handlers
}
else
m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
}
}
}
catch (Exception e)
@ -405,6 +406,9 @@ namespace OpenSim.Capabilities.Handlers
if (image != null)
image.Dispose();
if(managedImage != null)
managedImage.Clear();
if (imgstream != null)
{
imgstream.Close();

View File

@ -160,7 +160,6 @@ namespace OpenSim.Services.Connectors.Hypergrid
try
{
WebClient c = new WebClient();
//m_log.Debug("JPEG: " + imageURL);
string name = regionID.ToString();
filename = Path.Combine(storagePath, name + ".jpg");
@ -168,6 +167,7 @@ namespace OpenSim.Services.Connectors.Hypergrid
if (!File.Exists(filename))
{
m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: downloading...");
using(WebClient c = new WebClient())
c.DownloadFile(imageURL, filename);
}
else

View File

@ -1485,6 +1485,9 @@ namespace Amib.Threading
_isIdleWaitHandle = null;
}
if (_stpStartInfo.EnableLocalPerformanceCounters)
_localPCs.Dispose();
_isDisposed = true;
}
}