workaround potencial memory leak
parent
222a5b655f
commit
52a80f1742
|
@ -354,9 +354,9 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
byte[] data = new byte[0];
|
byte[] data = new byte[0];
|
||||||
|
|
||||||
MemoryStream imgstream = new MemoryStream();
|
MemoryStream imgstream = new MemoryStream();
|
||||||
Bitmap mTexture = new Bitmap(1, 1);
|
Bitmap mTexture = null;
|
||||||
ManagedImage managedImage;
|
ManagedImage managedImage = null;
|
||||||
Image image = (Image)mTexture;
|
Image image = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -365,25 +365,26 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
imgstream = new MemoryStream();
|
imgstream = new MemoryStream();
|
||||||
|
|
||||||
// Decode image to System.Drawing.Image
|
// 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
|
// Save to bitmap
|
||||||
mTexture = new Bitmap(image);
|
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
|
|
||||||
ImageCodecInfo codec = GetEncoderInfo("image/" + format);
|
|
||||||
if (codec != null)
|
|
||||||
{
|
{
|
||||||
mTexture.Save(imgstream, codec, myEncoderParameters);
|
myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,95L);
|
||||||
// Write the stream to a byte array for output
|
|
||||||
data = imgstream.ToArray();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
|
|
||||||
|
|
||||||
|
// Save bitmap to stream
|
||||||
|
ImageCodecInfo codec = GetEncoderInfo("image/" + format);
|
||||||
|
if (codec != null)
|
||||||
|
{
|
||||||
|
mTexture.Save(imgstream, codec, myEncoderParameters);
|
||||||
|
// Write the stream to a byte array for output
|
||||||
|
data = imgstream.ToArray();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -400,6 +401,8 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
if (image != null)
|
if (image != null)
|
||||||
image.Dispose();
|
image.Dispose();
|
||||||
|
|
||||||
|
if(managedImage != null)
|
||||||
|
managedImage.Clear();
|
||||||
if (imgstream != null)
|
if (imgstream != null)
|
||||||
{
|
{
|
||||||
imgstream.Close();
|
imgstream.Close();
|
||||||
|
|
|
@ -359,9 +359,9 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
byte[] data = new byte[0];
|
byte[] data = new byte[0];
|
||||||
|
|
||||||
MemoryStream imgstream = new MemoryStream();
|
MemoryStream imgstream = new MemoryStream();
|
||||||
Bitmap mTexture = new Bitmap(1, 1);
|
Bitmap mTexture = null;
|
||||||
ManagedImage managedImage;
|
ManagedImage managedImage = null;
|
||||||
Image image = (Image)mTexture;
|
Image image = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -370,25 +370,26 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
imgstream = new MemoryStream();
|
imgstream = new MemoryStream();
|
||||||
|
|
||||||
// Decode image to System.Drawing.Image
|
// 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
|
// Save to bitmap
|
||||||
mTexture = new Bitmap(image);
|
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
|
|
||||||
ImageCodecInfo codec = GetEncoderInfo("image/" + format);
|
|
||||||
if (codec != null)
|
|
||||||
{
|
{
|
||||||
mTexture.Save(imgstream, codec, myEncoderParameters);
|
myEncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality,95L);
|
||||||
// Write the stream to a byte array for output
|
|
||||||
data = imgstream.ToArray();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
|
|
||||||
|
|
||||||
|
// Save bitmap to stream
|
||||||
|
ImageCodecInfo codec = GetEncoderInfo("image/" + format);
|
||||||
|
if (codec != null)
|
||||||
|
{
|
||||||
|
mTexture.Save(imgstream, codec, myEncoderParameters);
|
||||||
|
// Write the stream to a byte array for output
|
||||||
|
data = imgstream.ToArray();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_log.WarnFormat("[GETTEXTURE]: No such codec {0}", format);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -405,6 +406,9 @@ namespace OpenSim.Capabilities.Handlers
|
||||||
if (image != null)
|
if (image != null)
|
||||||
image.Dispose();
|
image.Dispose();
|
||||||
|
|
||||||
|
if(managedImage != null)
|
||||||
|
managedImage.Clear();
|
||||||
|
|
||||||
if (imgstream != null)
|
if (imgstream != null)
|
||||||
{
|
{
|
||||||
imgstream.Close();
|
imgstream.Close();
|
||||||
|
|
|
@ -160,7 +160,6 @@ namespace OpenSim.Services.Connectors.Hypergrid
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WebClient c = new WebClient();
|
|
||||||
//m_log.Debug("JPEG: " + imageURL);
|
//m_log.Debug("JPEG: " + imageURL);
|
||||||
string name = regionID.ToString();
|
string name = regionID.ToString();
|
||||||
filename = Path.Combine(storagePath, name + ".jpg");
|
filename = Path.Combine(storagePath, name + ".jpg");
|
||||||
|
@ -168,7 +167,8 @@ namespace OpenSim.Services.Connectors.Hypergrid
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: downloading...");
|
m_log.DebugFormat("[GATEKEEPER SERVICE CONNECTOR]: downloading...");
|
||||||
c.DownloadFile(imageURL, filename);
|
using(WebClient c = new WebClient())
|
||||||
|
c.DownloadFile(imageURL, filename);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1485,6 +1485,9 @@ namespace Amib.Threading
|
||||||
_isIdleWaitHandle = null;
|
_isIdleWaitHandle = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_stpStartInfo.EnableLocalPerformanceCounters)
|
||||||
|
_localPCs.Dispose();
|
||||||
|
|
||||||
_isDisposed = true;
|
_isDisposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue