OxyImage seems to be leaking huge amounts of memory

Aug 28, 2013 at 12:48 PM
Using an ImageAnnotation on a plot, each updates sets the ImageAnnotation.ImageSource with a new OxyImage. I'm using a memory profiler which shows me that these OxyImage objects are duplicating their datasource and not being cleared away as they never come out of context whilst the plot is active.

I'm not sure I 100% understand what it going on here but this is definitely the cause of my issues as just commenting out the line which creates the OxyImage solves the issue. Over an hour or so I am getting over 1GB of memory being used which in turn ends up in the application crashing.
            using (Bitmap b = updateScatterArray())
                using (MemoryStream stream = new MemoryStream())
                    b.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
                    stream.Seek(0, SeekOrigin.Begin);
                    image = new OxyImage(stream);

                    foreach (ImageAnnotation a in IntensityPlotModel.Annotations)
                        a.ImageSource = image;

Any help / pointers greatly appreciated. This is getting quite urgent now!! Ta.
Aug 28, 2013 at 1:19 PM
It seems that each time I update the OxyImage, there is an imageCache which is getting added to.
Aug 28, 2013 at 1:26 PM
Yes, and if the image is not used at the next update, it should be removed from the cache. Let us know if you find the bug!
See also https://oxyplot.codeplex.com/workitem/10042
Aug 28, 2013 at 1:27 PM
Ah yes, this is what is happening here too. Just found that other thread!
Aug 28, 2013 at 1:35 PM
Can you show me where you think CleanUp() is getting called at the minute? Because I can't seem to find it being called anywhere?
Aug 28, 2013 at 1:47 PM
I have submitted a fix - let us know if this solves the problem!
Aug 28, 2013 at 1:52 PM
Brilliant! I just did the exact same thing as was going to post it here! haha! Thanks very much!