No, there is no way to avoid creation of temporary images (unless you come up with different algorithm). These temporary images will be automatically released by the system when there will be not enough memory. You can read more about it on the microsoft site: https://msdn.microsoft.com/en-us/library/0xy59wtx(v=vs.110).aspx
There is no need to run Garbage collect in your macro after every image as it's a time consuming operation.
I understand that the system is supposed to release memory automatically when needed. If so, then the images produced by my macro (which reside in memory) must not be the source of the "insufficient memory" errors generated by ImagePro after processing multiple images.
In that case we need a way to reproduce the problem. I duplicated your image 8 times and ran the batch with TestRoutine macro (disabling all CountImages calls)., there were no memory increase during or after the batch (in Task Manager).
When do you see the error? How many images can you process without errors? How much RAM do you have? Do you see errors processing the complete folder (without Monitor Folder option)? You may try to include Garbage Collect in the end of your macro to see if it changes anything. Can you post the exact error message/dialog, with error stack?
Answers
There is no need to run Garbage collect in your macro after every image as it's a time consuming operation.
Yuri
If so, then the images produced by my macro (which reside in memory) must not be the source of the "insufficient memory" errors generated by ImagePro after processing multiple images.
Could there be a different cause?
When do you see the error? How many images can you process without errors? How much RAM do you have? Do you see errors processing the complete folder (without Monitor Folder option)? You may try to include Garbage Collect in the end of your macro to see if it changes anything.
Can you post the exact error message/dialog, with error stack?
Thanks,
Yuri