AnthonyJones Posted July 6, 2009 Report Share Posted July 6, 2009 Our application seems to suffer from a memory leak when using the Chart.Export function. I can replicate the problem with the following code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.IO; using ChartFX.WPF; namespace WpfApplication1 { /// <summary> /// Interaction logic for Window1.xaml /// </summary> public partial class Window1 : Window { public Window1() { InitializeComponent(); btnTest.Click += new RoutedEventHandler(btnTest_Click); } void btnTest_Click(object sender, RoutedEventArgs e) { for (int i = 0; i < 25; i++) { Chart oTestChart = new Chart(); MemoryStream ms = new MemoryStream(); oTestChart.Export(FileFormat.Png, ms); ms.Close(); oTestChart = null; } GC.Collect(); } } } In this case, each time the button is clicked, the application's memory usage increases significantly and never seems to reduce again. The line "oTestChart.Export(FileFormat.Png, ms);" seems to be the culprit - if I remove it the memory usage doesn't increase. Is there any way of reclaiming the memory once the Export function has been used? We are using ChartFX.WPF.dll version 8.0.3439.25180. Thanks in advance! Quote Link to comment Share on other sites More sharing options...
AnthonyJones Posted July 7, 2009 Author Report Share Posted July 7, 2009 I've since noticed that the problem occurs when using FileFormat.Bitmap, FileFormat.Jpeg and FileFormat.Png but not when using FileFormat.Xml or FileFormat.XmlTemplate. It occurs regardless of whether the image output is to a memory stream or a file. Has anyone noticed this? Is there a fix for it? Quote Link to comment Share on other sites More sharing options...
MMCCPaulEden Posted July 20, 2009 Report Share Posted July 20, 2009 Anyone willing to comment on this? Quote Link to comment Share on other sites More sharing options...
JuanC Posted July 20, 2009 Report Share Posted July 20, 2009 We did found a leak and it only occurred when you exported a chart that was never rendered "normally" on the screen. You will need to download any build marked 3476 or later, additionally you will also have to manually invoke a Chart method call UnloadVisuals. I apologize for the delay, I thought I had posted a comment to this thread. JuanC Quote Link to comment Share on other sites More sharing options...
AnthonyJones Posted July 21, 2009 Author Report Share Posted July 21, 2009 Hi, thanks for your update. We have now upgraded to 8.0.3488.31327, but it hasn't made any difference to the memory leak issue. You said to manually invoke the UnloadVisuals method, but the chart object doesn't appear to have an UnloadVisuals method - have I misunderstood? Quote Link to comment Share on other sites More sharing options...
JuanC Posted July 21, 2009 Report Share Posted July 21, 2009 The method is there and it is public, we just made it non-browsable so that it does not appear on Intellisense. JuanC Quote Link to comment Share on other sites More sharing options...
AnthonyJones Posted July 23, 2009 Author Report Share Posted July 23, 2009 So it is! As you guessed, I was looking for it on Intellisense. Upgrading to 3488 and using chart.UnloadVisuals now appears to have fixed the problem - thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.