08-17-2009 06:16 AM
How can the following code create a memory leak? The TaskXData arrays are a fixed size, and I am not overrunning them or redeclaring them. As the application runs, the memory it is using increases by able 500 bytes every second. Thanks!
' Creating the tasks (in a loop)
Tasks(TaskCount).Control(TaskAction.Unreserve)
' Tell the task to take 100 readings of each channel at 10 kS/sec on the rising edge of the clock.
Tasks(TaskCount).Timing.ConfigureSampleClock("", SampleRate, SampleClockActiveEdge.Rising, _
SampleQuantityMode.ContinuousSamples, numSamples)
Tasks(TaskCount).Control(TaskAction.Verify)
' Create a reader object for this task.
reader(TaskCount) = New AnalogMultiChannelReader(Tasks(TaskCount).Stream)
reader(TaskCount).SynchronizeCallbacks = True
taskRunning = True
reader(TaskCount).BeginReadMultiSample(numSamples, myAsyncCallback, TaskCount)
TaskCount += 1
' Reading from the task
Public Sub AnalogInCallback(ByVal ar As IAsyncResult)
Dim TaskNumber As Byte
TaskNumber = CType(ar.AsyncState, Integer) 'cast the user object passed when registering the callback to an integer
Try
If taskRunning = True Then
Select Case TaskNumber
Case Is = 0
Task1Data = reader(TaskNumber).EndReadMultiSample(ar)
Case Is = 1
Task2Data = reader(TaskNumber).EndReadMultiSample(ar)
Case Is = 2
Task3Data = reader(TaskNumber).EndReadMultiSample(ar)
Case Is = 3
Task4Data = reader(TaskNumber).EndReadMultiSample(ar)
End Select
End If
Catch ex As Exception
MessageBox.Show("Unable to start reading.")
End Try
Try
reader(TaskNumber).BeginReadMultiSample(numSamples, AsyncCallback, TaskNumber)
Catch ex As DaqException
MessageBox.Show("Unable to start reading.")
End Try
End Sub
08-17-2009 06:33 AM