OxyImage seems to be leaking huge amounts of memory

Oystein Bjorke 10 lat temu 0
This discussion was imported from CodePlex

willmoore88 wrote at 2013-08-28 14:48:

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;
                    }

                    IntensityPlotModel.RefreshPlot(true);
                    OnPropertyChanged("IntensityPlotModel");
                }
            }
Any help / pointers greatly appreciated. This is getting quite urgent now!! Ta.

willmoore88 wrote at 2013-08-28 15:19:

It seems that each time I update the OxyImage, there is an imageCache which is getting added to.

objo wrote at 2013-08-28 15:26:

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

willmoore88 wrote at 2013-08-28 15:27:

Ah yes, this is what is happening here too. Just found that other thread!

willmoore88 wrote at 2013-08-28 15:35:

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?

objo wrote at 2013-08-28 15:47:

I have submitted a fix - let us know if this solves the problem!

willmoore88 wrote at 2013-08-28 15:52:

Brilliant! I just did the exact same thing as was going to post it here! haha! Thanks very much!