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 started to debug server COM to have a look at heap, gcroot etc.
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();
}
Despite having adequate RAM and not running resource-intensive software, there can be another situation where all available RAM gets used and performance degrades. This is known as a memory leak, and it happens when software fails to manage the available RAM correctly.
Running out of memory is the simplest way to identify a memory leak, and it's also the most common approach to uncovering one. That's also the most inconvenient way to find a leak. You'll probably notice your system slowing down before you run out of RAM and crash your application.
Very dangerous. Memory leaks in the kernel level lead to serious system stability issues. Kernel memory is very limited compared to user land memory and should be handled cautiously. Memory is allocated but never freed.
The brain is highly segregated. Multiple mechanisms ensure that different types of memories are processed independently. Nonetheless, information leaks out across these memory systems. Only recently has the diversity of these leaks been revealed.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With