我目前正在使用DynamicDataDisplay在用户界面上显示频谱,它运行良好但存在大量内存泄漏(大约1-2MB /周期)。当我使用新图表更新它时,它似乎不会释放所有内存。有没有其他人遇到过这个问题?我将如何解决它? 提前致谢。请参阅下面的代码
Dim P1Chart As New Microsoft.Research.DynamicDataDisplay.ChartPlotter()
Dim P1ChartDateTime As New Windows.Controls.Label()
…………………….
‘First remove old line graph from chart
ClearSpectrum(iTabIndex)
‘Load arrays with new spectral data
For SpectCtr = 0 To ScanElements
If Spectrum = ScanType.Absorbance Then
x(SpectCtr) = SpectCtr * 0.5 + 800.0 ‘Convert to wavelength if absorbance spectra
Else
x(SpectCtr) = SpectCtr
End If
y(SpectCtr) = sr.ReadLine()
Next
Dim xDataSource = AsXDataSource(x)
Dim yDataSource = AsYDataSource(y)
Dim xyDataSource As New CompositeDataSource(xDataSource, yDataSource)
Select Case StreamNumber
Case 1
P1Chart.AddLineGraph(xyDataSource, Colors.Red, 1, “Probe A”)
P1ChartDateTime.Content = String.Format(“Time: {0}, X-Axis: {1}”, FileSaveTime, xAxisTitle)
Case 2
P2Chart.AddLineGraph(xyDataSource, Colors.Red, 1, “Probe B”)
P2ChartDateTime.Content = String.Format(“Time: {0}, X-Axis: {1}”, FileSaveTime, xAxisTitle)
End Select
………
Private Sub ClearSpectrum(ByVal iTabIndex As Integer)
Dim nIndex As Integer
Select Case iTabIndex
Case 1
For Each child1 As IPlotterElement In P1Chart.Children
If TypeOf child1 Is Microsoft.Research.DynamicDataDisplay.LineGraph Then
RemoveList.Add(child1)
End If
Next
For Each child1 In RemoveList
P1Chart.Children.Remove(child1)
Next
……………..
RemoveList.Clear()