IMAQ images and Memory Management

I have not seen any code that disposed of Image instances (i.e., GetImaqImage()). I do, however, see code delete the source image and then use the underlying Image instance, which leads me to believe that ImageBase is not the owner of the Image instance. Am I to assume that they are managed by the IMAQ vision library. I can see generating a lot of these Images during a competition and although they tend to be small I can easily run out of memory if the resource is not freed.


Destructor of ImageBase:


Snippet from header:

	Image *m_imaqImage;

If you are working with pointers, you should just be able to delete the images out of memory each time through the loop once you are done processing them.

Image *genericImage = NULL;
//Code to get value and store it in genericImage
delete genericImage;

For Image objects you should use imaqDispose.

Ah, I have yet to look into the inner workings of the 7000 lines of nivision.h… I just went off of my prior C++ experience. Sorry for the misinformation.

There are versions of GetImage that take a pointer to an Image so you can allocate your own image data structure (once using new HSLImage() then set the size) and use it over and over again. This will be a bit faster. When programming in a real-time environment it is better to NOT be doing memory allocations or formatted output in loops where you hope to have deterministic (execute in the same amount of time each time through) performance.