peacefulmember
peacefulmember

Reputation: 305

Possibly memory leak OR?

Would appreciate any kind of help here.

A brief description about scenario -

There is a COM+ running on server (written in C#). The task of this COM is to take a file name, page number of a multi-paged tiff file and the resolution to convert it to a gif file image. This COM is called from a web application using a proxy. The web site gets the converted image and displays in the requested resolution. For printing - it makes 2 request - 1st for display resolution, 2nd in full resolution (which gets printed using window.print()).

Problem -

After sometime server goes out of memory and images are not getting displayed on web site. Server needs to be restarted periodically.

Error

EventType clr20r3, P1 imageCOM.exe, P2 1.0.0.0, P3 4fd65854, P4 prod.web.imaging, P5 1.0.0.0, P6 4fd65853, P7 1a, P8 21, P9 system.outofmemoryexception, P10 NIL.

Here is the error(s) on the web server (these continuously appear every minute) ….

System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
   --- End of inner exception stack trace ---

I do not have access to production server, but error sent by sysadmin states OutOfMemory.

Thus, assuming memory leak and focusing on it - my findings so far with limited experience of handling this kind of situation -

I know I gave very vague description, but I need some kind of lead to detect the real issue on server.

EDIT: Image object has been disposed like

Bitmap retVal;

      using (MemoryStream buffer = new MemoryStream(doc.FileData, 0, doc.DocumentSize, false, false))
      {
        using (Bitmap original = new Bitmap(buffer))
        {
        //select the page to convert and
        //perform scaling - full resolution or the requested resolution.  
        }
      }

      using (MemoryStream buffer = new MemoryStream())
      {
        retVal.Save(buffer, ImageFormat.Gif);
        retVal.Dispose();
        return buffer.GetBuffer();
      }

Upvotes: 6

Views: 728

Answers (2)

Paccc
Paccc

Reputation: 1211

Make sure you are disposing the Image objects (such as Bitmap) after you're done using them. I'm guessing you're opening the tiff image as a bitmap and rescaling it and then saving it again as a gif. If you don't dispose the Bitmap it will leak memory (usually several MB each time depending on the size of the image).

Upvotes: 2

Avichal Badaya
Avichal Badaya

Reputation: 3619

I think your 1st point might be the reason for the issue. You might try reducing the cache expiry time and check how much time it is taking to get outofmemory error again, you might have to make changes in your algorithm to avoid this situation. Your 2nd should not be the reason for the error.

Upvotes: 1

Related Questions