Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does IMAQ Dispose prevent second execution of program?

I have an applicaton that creates many images. I want to dispose of all image once at the end of the program. If I do this, it works fine the first time that I run it, but the next times I get "Not an Image" errors at various locations. I can not run it again successfully without shutting down Labview. The Dispose really doesn't occur until the very end.

What is causing this, and do I really need to dispose of my images on a Windows 2000 OS?
0 Kudos
Message 1 of 11
(4,712 Views)
I suspect your program is set up to only allocate images on the first iteration of a loop. When you run the program a second time, your "initialized" variable is True so it doesn't do the image allocation again. It is really hard to troubleshoot something like this without looking at the code.

If you reuse the same image names, you don't have to dispose all your images. If you are always using different names, you need to dispose of them so that you don't run out of memory. Once you exit LabVIEW, they are all disposed of automatically.

Bruce
Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 11
(4,712 Views)
Bruce-

There are no loops that allocate images. The program starts with a file open and goes from there every time. I cannot post this, so I will probably contact NI Support about this. Thanks.

Brian
0 Kudos
Message 3 of 11
(4,712 Views)
As long as you have an IMAQ Create VI and IMAQ Dispose VI for each image you are opening, it should be fine. Make sure that these two functions match up. Also, take a look at the Memory Management document for more information:
http://zone.ni.com/devzone/conceptd.nsf/webmain/4A350323D583151C86256AE3007608B6

Regards-
Julie S.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 11
(4,712 Views)
I would prefer to use a single Dispose at the end, because some images are created in a sub-vi, but not used till somewhere later in the program. I read the Memory Management document, and I believe I am doing things the correct way. Shouldn't the dispose all setting work and be acceptable?
0 Kudos
Message 5 of 11
(4,712 Views)
You can definitely use the IMAQ Dispose VI to get rid of all the images from IMAQ Create if the All Images? input is set to True. Having images created in a subVI shouldn't affect the behavior either - I created a small VI that does this and it will run multiple times. Perhaps you can create a small VI that exhibits the behavior you mention and attach it to this forum, so that I can take a look at it.

Regards-
Julie
Download All
0 Kudos
Message 6 of 11
(4,712 Views)
Julie-

Haven't looked at your example yet, but yesterday I went into my program and added an IMAQ Dispose for every Create. I still left a Dispose all at the very end, just to test it. Now, it will run for several times before I get the error.

I can send you my program, but I just can't publicly post it. Let me know how to do this.

Thanks

Brian
0 Kudos
Message 7 of 11
(4,712 Views)
Can you reproduce the issue in a smaller version of your code, with just the VIs that exhibit the behavior? Then you can post it here. If not, please strip the code down to only the necessary functions and post it to our FTP site: ftp://ftp.ni.com/incoming - people external to NI cannot download anything on the incoming FTP site, so you don't need to worry about that.
Thanks -
Julie
0 Kudos
Message 8 of 11
(4,712 Views)
Julie-
I posted a zip file titled "IMAQ Dispose Problem" on the ftp site. I believe it includes everything you need. Let me know if you have any questions.

Thanks,
Brian
0 Kudos
Message 9 of 11
(4,712 Views)
After looking through your code, I'm still not sure why it takes four runs to have an error show up. However, the reason you are getting that error when setting the IMAQ Dispose all to True is because it is in a For loop, and you are therefore calling it the same number of times as elements in your array. (The loop is indexed by the array of images.) So you are calling it 8 or so times to dispose of all images, when there are no images to dispose of. I monitored the memory usage when continuously running the program without a dispose all at the end, and it doesn't seem like you've left any of the images open, where the memory usage would steadily increase. I couldn't isolate the issue though, or
reproduce on my own, so it is very hard to say what was causing the error.
As long as you leave the all images? input as False, you should be fine.

Regards-
Julie S
0 Kudos
Message 10 of 11
(4,712 Views)