这不是C1控件的问题,这是.NET机制。比如在window上只放一个MS button,如上操作,情况一样。GC不会再窗口关闭后立即回收。
另外,vshost进程会包含一些debug信息,所以它保留了部分对象,也是无法立即回收的原因。
不过我们提供了一段代码,可以优化这个问题,功能参考- public partial class WindowChart : Window, IDisposable
- {
- public WindowChart()
- {
- InitializeComponent();
- //Chart.Data.Children.Add(new XYDataSeries
- //{
- // RenderMode = RenderMode.Default,
- // XValuesSource = ReviewCpetParas.GetInstance().Time,
- // ValuesSource = ReviewCpetParas.GetInstance().Volume,
- // ConnectionStrokeThickness = 2,
- // ConnectionStroke = new SolidColorBrush(Colors.Red),
- //});
- //Chart2.Data.Children.Add(new XYDataSeries
- //{
- // RenderMode = RenderMode.Default,
- // XValuesSource = ReviewCpetParas.GetInstance().Time,
- // ValuesSource = ReviewCpetParas.GetInstance().Flow,
- // ConnectionStrokeThickness = 2,
- // ConnectionStroke = new SolidColorBrush(Colors.Red),
- //});
- }
- public void Dispose()
- {
- this.Chart.Content = null;
- this.Chart.View.DataContext = null;
- this.Chart.View = null;
- this.Chart.Data.DataContext = null;
- this.Chart.Data = null;
- this.Chart.DataContext = null;
- this.Chart2.Content = null;
- this.Chart2.DataContext = null;
- this.Chart2.View = null;
- this.Chart2.Data.DataContext = null;
- this.Chart2.Data = null;
- this.Chart2.DataContext = null;
- Root.Children.Clear();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Dispose();
- this.Close();
- GC.WaitForPendingFinalizers();
- GC.Collect();
- }
- }
复制代码 |