We have scenario of image upload in ASP.NET MVC3.
Controller
public ActionResult Upload(IEnumerable<HttpPostedFileBase> images, SomeViewModel model) { foreach(var i in images) { ... byte[] fileBytes = i.InputStream.GetBytesArray(); byte[] image = _imageManager.Resize(fileBytes, MaxImageWidth, MaxImageHeight, true); ... } }
ImageManager
public byte[] Resize(byte[] content, int width, int height, bool preserveAR = true) { if (content == null) return null; WebImage wi = new WebImage(content); wi = wi.Resize(width, height, preserveAspectRatio); return wi.GetBytes(); }
So we recieve image from client as HttpPostedFileBase. We pass byte[] fileBytes to Resize method of imageManager. Image manager is creating new WebImage instance, then Resize image and transform it to byte[] again.
When debugging this code, at the moment I pass wi.GetBytes() line, my memory usage raises drastically (for at least 500mb). I`m uploading image of 10mb. When uploading smaller size photos (~1.5mb) memory consumption is normal.
What can be the cause of this, and can this be fixed somehow?
Thank you