LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Memory leak in IMAQ Write PNG File

Hi,

 

I have a labview program that I'm using to do Speckle Patter Interferometry - it takes an image, takes a second image after some time, then subtracts the original image from the first and saves the subtraction.  The process reveals fringes on an object deformed on wavelength scales.

 

The problem currently is that the program seems to have a memory leak.  When I run the program, the amount of memory being used (according to Windows Task Manager) just keeps going up and up then after about 20 minutes, it crashes with the error:

 

Error 1074396159

Not enough memory for required operation

 

The error is normally when the file tries to write the png file - though that is the part of the program that takes the most time so it could just be coincidence that it happens at this point in the loop.

 

I've tried using the labview profiler (output attached), but can't see a particular VI that is using an abhorrent amount of memory.

 

I'm fairly stuck for ideas - I've attached a library with the VI and its sub VIs - if anyone would be so kind as to give me a hand I'd be very much appreciative.  I realise that my code is quiet messy - this is my first attempt at labview (albeit quite a long way into my first attempt) so any suggestions would be much appreciated also.

 

Thanks
Sam

Download All
0 Kudos
Message 1 of 4
(3,943 Views)

Hi people,

 

I found the problem - or at least the main problem.  I wasn't deleting IMAQ Images that I had created within the loop - so it was creating a new image (or pointer or whatever it actually does behind the icons) without that being deleted.

 

If anyone started looking at my code and has any suggestions for me to improve it, I would very much like to hear them still.

 

Thanks
Sam

0 Kudos
Message 2 of 4
(3,932 Views)

Hi Sam, 

 

I'm glad to hear that you managed to fix the problem in your code. I have had a look at the code you posted and I have a few suggestions on how you can improve it.

 

In your code you haven't included the error clusters from the VIs. Most sub VI functions included in LabVIEW will have an Error In and Error Out port that will transfer any error information through the VI. If an error does occur in the code, the error will be passed through the rest of the VI. If a sub VI or function receives an error at its error in port the VI will not execute and the error will pass through until it reaches the end of the VI. At the end of a the VI there needs to be an Error Handler function to display the error information. As error information flows through the VI the same as the data, using error clusters is a good way to determine the flow of data through a VI. This is a good way to determine the data flow through the VI as opposed to Sequence Structures which should be used in moderation.  

 

I have taken a segment of you code and made some minor modifications to demonstrate how error clusters can be used (see screenshot below).  

 

 

 code example.PNG

 

Error clusters can be implemented into any logic for the stop condition of a while loop. The Unbundle by Name using the Status option can be used in conjunction with the error cluster to produce a boolean output depending on if an error has occurred. If an error does occur, the function will produce a true and if an error does not occur it will produce a false. The error cluster can also be expanded by hovering the mouse over the top or bottom of the function and dragging the grey box up or down. This is useful for when you want to produce multiple outputs from the same data, such as the histogram data in your VI.

 

Another thing I noticed in you code was some redundant logic. You had set the Stop button default on your front panel to true, which meant that an inverter had to be used to stop the first while loop and the stop condition in the last while loop had been changed to Continue if True. If you had kept the stop button default to False and the stop condition of the last while loop to Stop if True, the inverter on the first while loop would not be needed. This however is only a small issue but its something you could keep in mind when writing other code.

 

Hopefully these suggestions will help you to further develop you LabVIEW code. I understand that implementing these suggestions into you current code could be an issue due to the size of it, but they are good features to consider when developing any code in the future. 

 

If there is anything you are unsure of please do not hesitate to post any questions. I will be more than happy to assist you.

 

Kind Regards 

 

 

Jason W.
Applications Engineer
National Instruments UK & Ireland
0 Kudos
Message 3 of 4
(3,895 Views)

Hi

 

 

Can you please your updated VI,s

 

thanks

 

 

0 Kudos
Message 4 of 4
(3,762 Views)