This project has moved. For the latest updates, please go here.

Memory leak in MagickImage.Read

Sep 10, 2015 at 7:38 PM
I'm trying to track down a heap memory leak and it seems to be some unmanaged memory allocated by ImageMagick (using 7.0.0.0018 Q8 x64). And I'm wondering if it's something that I'm doing wrong. I have a class that reads in an image from a stream into a MagickImage member variable. Are there any obvious best practices that I might be violating that could lead to memory leaks if not obeyed? For example, I think the leak may be coming from MagickImage.Read, do I need to call Dispose first to make sure? There are cases where I call Ping first (in case I only need to read metadata) and then Read if I need the image. Would I need to clear anything out in between?

Thanks for any help!

tim
Coordinator
Sep 11, 2015 at 11:12 AM
Would it be possible to create a small example program that demonstrates this behavior and share it on something like dropbox? This program should contain a loop that is executed a lot of times so I can see 'the memory grow'.

Are you disposing your MemoryStream? Magick.NET won't do that for you. It is safe to call Read and Ping on the same image, this should not leak.
Sep 11, 2015 at 7:26 PM
Which MemoryStream are you referring to? I would love to throw together a little program, the problem is I can't reproduce it. I only see it on production boxes so I'm trying to use xperf to track it down but I'm having trouble getting good stack traces. I just see lots of unfreed heap allocations of 4,102 bytes. Can I just send you my code file that does all of the interaction with MagickImage privately?
Coordinator
Sep 11, 2015 at 7:42 PM
Edited Sep 11, 2015 at 7:53 PM
Sorry about the MemoryStream confusion :) You wrote that you read the image from a Stream and I read MemoryStream.

The number 4102 is really close the the size we use for string buffers which is 4096 but that still leaves 6 bytes. You could send me your code but I am not sure if I will be able to track down the issue with that. Contact me through CodePlex and we can continue the conversation there.
Sep 22, 2015 at 12:05 PM
For anyone else who stumbles on this thread, Dirk tracked down the leak and as of version 7.0.0.0019 my issue has been resolved.