From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview IMAQ Memory Leak

Solved!
Go to solution

Hello All

 

I am run a subVI in order to capture images at given times within a larger case-structured VI (please see the attached).  The main VI will cyclically call upon this subVI.  The issue that I am experiencing is that every time the subVI is called, approximately 8 Mb of RAM are consumed and never released.  Given that this subVI will be called at least 4000 times in the course of the primary VI, this would lead to a RAM consumption of over 32 Gb.  Any help to eliminate the memory loss would be appreciated.

0 Kudos
Message 1 of 7
(4,250 Views)
Solution
Accepted by topic author Bonzey1986

You're repeatedly opening and and closing the IMAQdx camera reference.  This is likely the issue and is not recommended. 

 

Move the IMAQdx Open Camera and Close Camera functions outside of the subVI and call them only once, at startup and shutdown respectively.

0 Kudos
Message 2 of 7
(4,239 Views)

To add to the above, you forgot to actually wire any image reference to the IMAQ Dispose so each iteration you are creating a new image reference, filling it up with an image and then never getting rid of it. You could probably just wire the image reference to that dispose but the better solution would be to open the image reference outside of your loop and reuse the same reference. No need to create and destroy a reference each loop, create it once, keep using it in the loop, and then get rid of the reference when your program is done.

Matt J | National Instruments | CLA
Message 3 of 7
(4,212 Views)

@Jacobson-ni wrote:

To add to the above, you forgot to actually wire any image reference to the IMAQ Dispose so each iteration you are creating a new image reference, filling it up with an image and then never getting rid of it. You could probably just wire the image reference to that dispose but the better solution would be to open the image reference outside of your loop and reuse the same reference. No need to create and destroy a reference each loop, create it once, keep using it in the loop, and then get rid of the reference when your program is done.


I did exactly that in a project, forgetting the Imaq picture reference. The program ran fine but each picture increased the memory with about 1Mb, so after a few hours the computer ran out of memory. It was easy enough to fix once i found it (bug smashing can be hard).

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 7
(4,202 Views)

Even though the IMAQ Dispose.vi doesn't have a picture reference wired to it, the code block in question should always use the same memory location (pointer) for the picture because the camera name/alias is wired as the image name input to the IMAQ Create.vi. 

 

Therefore each time the code executes, it should obtain the same image reference/pointer even though it's not being closed afterwards.

 

Simple solution and best practice is to place initialize, create and destroy/release functions outside of the sub-process.

 

 

0 Kudos
Message 5 of 7
(4,177 Views)

Thank you all for your feedback.  However given that the subVI has a request deallocation built in, should this not eliminate the allocated memory set when the subVI closes?  Or does Labview treat IMAQ memory differently?

0 Kudos
Message 6 of 7
(4,167 Views)

1) Request Deallocation is not a tool that should be used normally. It does in most situations not do what you think it should do, and in many cases makes your VI slower.

2) Yes IMAQ Images are not the same as other LabVIEW data types like strings and arrays. As far as LabVIEW is concerned an IMAQ images is a handle whose contents is managed by the IMAQ Vision function. You can think of it as a pointer. The LabVIEW compiler does NOT manage the contents of the IMAQ image (except deallocating it when you close LabVIEW entirely). The reason for that is that the normal LabVIEW dataflow rules are not ideal for managing huge data BLOBs like what an image often contains. So the developers created the special datatype which as far as LabVIEW is concerned is more like a pointer and the IMAQ Vision functions manage it explicitly.

Rolf Kalbermatter
My Blog
Message 7 of 7
(4,155 Views)