Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

MEMORY LEAK IN CWGRAPH? Application slowly uses up all memory. VB6 sp4, NT4 sp4, Tried VB6 sp4, NT4 sp6 both machines show same problem. Shut-down the VB app releases memory. Only happens when using the CWGraph. Any IDEAS?

The code used to plot the graph data is as follows. If I insert an Exit sub at the beginning of this subroutine to bypass the graph, no memory usage occurs. I have also tried using the 'DoEvents' commad at the end of the subroutine to ensure windows clean-up but that did not help. Code...
Private Sub objHandleEvents_UpdateMeasurementGraph(boolXAxisAuto As Boolean, boolYAxisAuto As Boolean, _
dblXMinimum As Double, dblXMaximum As Double, _
dblYMinimum As Double, dblYMaximum As Double, _
intLineStyle As Integer, conLineColor As ColorConstants, _
intPointStyle As Integer, conPointColor As ColorConstants, _
arGraphData As Variant, boolClear As Boolean)

'*****************************
'* Set generic error handler *
'*****************************
On Error GoTo HandleError

'*************************
'* Variable Declarations *
'*************************
Dim intCounter As Integer
Dim boolRunTimeError As Boolean
Dim objXAxes As CWAxis
Dim objYAxes As CWAxis
Dim objPlot As CWPlot
Dim arGraphXData() As Variant
Dim arGraphYData() As Variant

'*******************
'* Clear the graph *
'*******************
If boolClear = True Then
gphMeasurementGraph.ClearData
End If

'***************************
'* Create Object Instances *
'***************************
Set objXAxes = gphMeasurementGraph.Axes.Item(1)
Set objYAxes = gphMeasurementGraph.Axes.Item(2)
Set objPlot = gphMeasurementGraph.Plots.Add

'**************************
'* Make the graph visible *
'**************************
gphMeasurementGraph.Visible = True

'*************************
'* Setting up the X-Axis *
'*************************
objXAxes.Ticks.MajorGrid = True
objXAxes.Ticks.MajorGridColor = vbWhite
objXAxes.AutoScale = boolXAxisAuto
If (Not objXAxes.AutoScale) Then
objXAxes.SetMinMax dblXMinimum, dblXMaximum
End If

'*************************
'* Setting up the Y-Axis *
'*************************
objYAxes.Ticks.MajorGrid = True
objYAxes.Ticks.MajorGridColor = vbWhite
objYAxes.AutoScale = boolYAxisAuto
If (Not objYAxes.AutoScale) Then
objYAxes.SetMinMax dblYMinimum, dblYMaximum
End If

'***********************
'* Setting up the Plot *
'***********************
objPlot.LineStyle = intLineStyle
objPlot.LineColor = conLineColor
objPlot.LineWidth = 3
objPlot.PointStyle = intPointStyle
objPlot.PointColor = conPointColor

'******************
'* Chart the data *
'******************
ReDim arGraphXData(LBound(arGraphData) To UBound(arGraphData))
ReDim arGraphYData(LBound(arGraphData) To UBound(arGraphData))
For intCounter = LBound(arGraphData) To UBound(arGraphData)
arGraphXData(intCounter) = arGraphData(intCounter, 0)
arGraphYData(intCounter) = arGraphData(intCounter, 1)
Next intCounter
objPlot.ChartXvsY arGraphXData, arGraphYData

'Tried "DoEvents" Here

'****************************
'* Destroy object instances *
'****************************
Set objXAxes = Nothing
Set objYAxes = Nothing
Set objPlot = Nothing

'Tried "DoEvents" Here

ExitHere:
If (boolRunTimeError) Then
Unload Me
Else
Exit Sub
End If

HandleError:
Select Case Err.Number
Case Else
boolRunTimeError = True
Call HandleErrors(Err.Number, Err.Description, "objHandleEvents UpdateMeasurementGraph Sub")
End Select
Resume ExitHere

End Sub
0 Kudos
Message 1 of 2
(3,592 Views)
So does your app seem to use more memory each time this subroutine is called, or do you run out of memory just during one call?

Since you are using the ChartXvsY method of the graph you might want to try setting the ChartLength property to a fixed value, because the "Automatic Calculation" only works with the ChartY method. The ChartLength property is the same thing as the "Chart History" that can be set via property pages, and determines how many datapoints the graph will store internally before overwriting them. For more information you can look at the Componentworks Reference on your pc under the ChartLength property.

If this doesn't resolve the behavior you may want to contact National Instruments technical support directly through the webform at www.ni.com/ask
so that we can try and reproduce it. Please give us a detailed description of your hardware and software as well as a narrowed down sample of your code that is runnable and exhibits the behavior to speed along the process of support.

Jason F.
Applications Engineer
National Instruments
www.ni.com/ask
0 Kudos
Message 2 of 2
(3,592 Views)