11-23-2015 06:34 AM
Hi,
I use a Framegrabber DLL to read a analog video stream. When the VI runs about 6 hours LabVIEW shows an error message "memory is full".
When the VI is running and I have a look to the memory usage in the task manager I see that the memory is increasing continously.
I suppose the bug is inside the while-loop but I can't fix it.
It can also be a problem of the DLL but I don't know where to start. Can it somthing to do with references?
Solved! Go to Solution.
11-23-2015 07:44 AM
Yes, it's absolutely to do with references.
Any time you create a reference, or a reference is returned from a method/property node, that reference needs to be closed. It's a common trap that people usually do the first one, but forget about the second one. For example, in the while loop you have a reference returned from 'LockNextImage' and also 'ToBitmap' which are generated within the loop but aren't closed within it so those references are left hanging.
The desktop execution trace toolkit is a very handy tool for checking for references that are left open when you finish executing. When you stop the VI, you'll see a whole load of yellow rows for references that weren't closed during execution.
You obviously need to be careful not to close a reference before you are finished with it (e.g. closing the reference from 'ToBitmap' should be done after the PictureBox) but you'll soon get an error if you close it early.
You should prioritise closing any references that are obtained within any loops - that's where you'll have a memory leak. If you open a reference once and forget to close it it generally isn't too much of a problem but it is if you do it repeatedly every millisecond!
11-23-2015 07:50 AM
Hi Sam_Sharp,
I understand the problem with the references, but I need the referenc outside the while for other function calls like ImageFormat or Device->Stop.
How can I solve this?
11-23-2015 07:59 AM
I didn't say you need to close all references inside the loop - only the ones that are generated inside the loop.
I've highlighted all of the places (I think) in your screenshot where you've generated/obtained a reference:
I count 11 places where references are obtained (there will be more because of arrays of references) and only 3 close references. Inside the loop, after you've used the LockNextImage and ToBitmap references you can then release them (i.e. place them after the ConvertImage/UnlockNextImage and the PictureBox nodes) as they are not used outside of the loop.
11-23-2015 08:16 AM
Please have a look to the screenshot.
I have closed the references. Is it what you mean?
11-23-2015 08:24 AM - edited 11-23-2015 08:24 AM
It's messy (folded wires), but yes, it looks like that would work.
Like I said - you can test it yourself by using the Desktop Execution Trace Toolkit - turn off all of the options except the one about references and then run / stop your application. It will show you all of the orphaned references.
11-23-2015 08:39 AM
Yes okay it works. I saw it with the memory usage.
Many thanks.
Have a nice week.
11-23-2015 08:42 AM - edited 11-23-2015 08:42 AM
As a small tweak i'd place that Live Image terminal before the loop and use a feedback node of it until you exit the loop and use its close ref, instead of doing it every loop.
/Y
11-23-2015 09:17 AM
@Michael65589 wrote:
Yes okay it works. I saw it with the memory usage.
Many thanks.
Have a nice week.
Feel free to Kudos my post or mark one as the solution if they have been helpful 🙂