Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory Leak During Continuous Acquisition

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

0 Kudos
Message 1 of 2
(2,515 Views)
Nevermind...looks like it is happening while my data file is being written.  Please delete this message.
0 Kudos
Message 2 of 2
(2,513 Views)