title: Out Of Memory exception on System.Drawing in a Windows Service
body: <p>I am getting in out of memory exception while using system.drawing intensively in my windows service.</p>
  
  <p>here is a part of my code:</p>
  
  <pre><code>FileStream fs = new FileStream(ImagePath, FileMode.Open, FileAccess.Read);
  img = (Image)Image.FromStream(fs).Clone();
  </code></pre>
  
  <p>The exception is not only raised in this point, it is also raised in other points sometimes where it involves drawing, cropping, resizing, image copy</p>
  
  <p>I am always disposing all the used objects.</p>
  
  <p>I saw this article about the "Out of memory exception" in system.drawing
  <a href="https://stackoverflow.com/questions/1108607/out-of-memory-exception-on-system-drawing-image-fromfile">here</a></p>
  
  <p>and while it is very similar to my case it is different because my testing data is a repeated chain of 40 images, so if there is an issue in one of them it should appear quickly from the first cycle.</p>
  
  <p>I saw the limitation mentioned <a href="http://msdn.microsoft.com/en-us/library/system.drawing.aspx" rel="nofollow noreferrer">here</a></p>
  
  <p>it says that we should not use system.drawing on Win/Web services.</p>
  
  <p>OK, I need to use it with a windows service for massive images processing, what are the alternatives if any?</p>