Hi Alex,
We found what was causing the "unable to write data to stream" error. It was an error on our part.
However, we are seeing what we believe is a memory leak when the Save fails.
Here's our code:
Code:
for (int i = 0; i < 1000; i++)
{
try
{
using (FileStream fs = new FileStream("C:\\06-0000313236-03-05_20070904212918847.jpg", FileMode.Open))
{
Byte[] bytes = new Byte[fs.Length];
fs.Read(bytes, 0, int.Parse(fs.Length.ToString()));
using (MemoryStream ms = new MemoryStream(bytes))
using (Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(ms))
{
int iImgHeight = bitmap.Height;
int iImgWidth = bitmap.Width;
if (bitmap.IsCmyk)
{
using (Aurigma.GraphicsMill.Transforms.PixelFormatConverter pixelConverter = new Aurigma.GraphicsMill.Transforms.PixelFormatConverter())
{
pixelConverter.DestinationPixelFormat = Aurigma.GraphicsMill.PixelFormat.Format32bppArgb;
pixelConverter.ApplyTransform(bitmap);
bitmap.Save(ms, new Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(100, false));
}
}
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
Attached is the image that we're using to test.
An exception occurs on the Save (which is ok for right now as that's what we're testing), but we're not seeing the memory released through the automatic calling of the Dispose method by the using statement. To double check we wrote the using statement as a try/catch/finally block and saw the same results.
We also tested adding a GC.Collect in the exception handler to force the GC to collect, but didn't see any improvement.
The leak isn't huge, but it's steady ~300K a call.
We think the leak is happening because Aurigma.GraphicsMill.StreamWrapper associated to the Bitmap isn't being disposed of properly. That's what our MemoryProfiling is showing us at least.
We're seeing the number of instances of System.Byte[], System.IO.MemoryStream, and Aurigma.GraphicsMill.StreamWrapper grow by the number of loop iterations.
Do you see anything that we're doing wrong and if you agree that there's a memory leak on your end, do you have a work around?
Thx, Joel
JRumerman attached the following image(s):
