0

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!

RSNL
  • 213
  • 3
  • 15
  • What happens if you evaluate `this.imagePath`, and copy/paste that into a browser address bar? Do you see the image? Is there an error message? If so, what doe sit say? – Mawg says reinstate Monica Aug 20 '17 at 09:13
  • Thank you for you're comment. Turns the method was not called correctly now it works fine but is still have the memory leak. I have adjusted this questionf for the leak. – RSNL Aug 20 '17 at 15:55
  • You allocated memory for the variable memorystream and returned it. Does the caller ever free it? – Mawg says reinstate Monica Aug 20 '17 at 18:31
  • Hi, thank you for you're comment. I tried to close/dispose the stream. But then the image is not shown. I post my code in the post. Do you have any idea? – RSNL Aug 21 '17 at 17:14

0 Answers0