Hello eler,
Thank you for contacting NI Support.
I had a look at your code and I have found why you are seeing your memory usage increase so drastically.
Near the top of your code you declare
Dim CurImage As New NationalInstruments.CWIMAQControls.CWIMAQImage which is a global variable that reads in the image.
In your "
Private Sub GetNextImage(ByRef Image As NationalInstruments.CWIMAQControls.CWIMAQImage)" function
You have:
Dim filename As String
filename = Dir(CurDir() & "\*.bmp")
Image = New NationalInstruments.CWIMAQControls.CWIMAQImage
' Read the image and store it in the collection
CWIMAQVision1.ReadImage(Image, CurDir() & "\" & filename)
'Attach the image to the viewer
CWIMAQViewer1.Attach(CurImage)
Basically each iteration you are creating a new CWIMAQImage called "Image" and you do the ReadImage function with it; your viewer is using the CurImage variable which is a global created at the start of your whole application. You are not releasing the memory allocated to Image each time.
Instead of creating a new image each time you read one in, you should use the CurImage global variable to store the information. Remove the "Image" declaration and change the parameter of "CWIMAQVision1.ReadImage" to CurImage and this should get rid of your memory leak. The above code should read as this:
Dim filename As String
filename = Dir(CurDir() & "\*.bmp")
' Read the image and store it in the collection
CWIMAQVision1.ReadImage(CurImage, CurDir() & "\" & filename)
'Attach the image to the viewer
CWIMAQViewer1.Attach(CurImage)
I hope this helps!
Cheers,
Rishi L
National Instruments
Applications Engineer