Depending upon what your script is doing it, and how it's doing it, it's unlikely that the undo cache is filling up or causing an issue. Most scripting commands do not create an undo state. Therefore, you could run a script that executes 1000 commands, and still only have one undo point. Some commands do create undo points (and i've made it a mission of mine to try to avoid these whenever possible), however. the app.executeMenuCommand() method creates an undo point in most cases. And also duplicating any artwork from one file to another creates an undo point.
Memory leakage has been a problem for a while with scripting illustrator. Some methods for preventing, or at least minimizing, these issues are as follows.. Perhaps some others will jump in and share their successes in this area as well.
- when batching files, you should open all the necessary files first, then execute your script's functionality, then close all of your files.
- something about opening/processing/closing files one after the other exacerbates the memory issue.
- declare your variables outside of loops.
I thought my list was going to be longer... anyway.. Taking these steps has had a profound effect on my workflow. Hopefully they'll help you as well.
If you want to try out the undo state thing, there's a setting in your Illustrator Preferences under the performance tab where you can change the number of undo states to keep. however, i think this fact nullifies your initial suspicion. there is a finite amount of undo states that you can keep.