I have a aurelia client that gets a image from my asp.net server via my API. The image is served from the server that holds a Emgu CV UMat var. With the following method in my controller i get the image and it is displayed correctly.
This method results in memory leakage and i can't seem to get to the orgin (not calling the method, means no leak):
Update, i tried Mawg's suggestion but when i close the stream it will not show the image. The leak is gone then but there is no image.
[System.Web.Http.HttpGet]
[System.Web.Http.Route("dummymethod3")]
public HttpResponseMessage Get2()
{
HttpResponseMessage response = new HttpResponseMessage();
try
{
Console.WriteLine("Get image 3");
ddEngine.sem.WaitOne();
var memoryStream = new MemoryStream();
ResultImage.Bitmap.Save(memoryStream, ImageFormat.Png);
memoryStream.Position = 0;
var result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new StreamContent(memoryStream);
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
memoryStream.Close();
memoryStream.Dispose();
ddEngine.sem.Release();
return result;
}
catch
{
Console.WriteLine("Ex");
}
return response;
}
I have tried to call the collector at several places in the code like:
GC.Collect();
GC.WaitForPendingFinalizers();
When doing this it releases resources but the memory usege is slowly increasing. When not calling the get method there is no increase!
My client code looks like this:
updateImageSrc() {
let dt = new Date();
let baseUrl = "http://localhost:8080/api/status/dummymethod3";
this.imagePath = baseUrl + "?t=" + dt.getTime();
}
And the html
<img id="img" src.bind="imagePath"/>
Any suggestions are welcome!