Sure Undo may eat a lot of memory but is expected for a script to always support Undo

Maybe will be possible add a option in the script to let the active layer unchanged and instead create new layer(s) or a new image

Because if the script create new layer(s) but without modify the rest of the image undo may even be seen as superfluous:
to undo would be just needed delete the new layer or the new image

But that should be also clear to the users, in case maybe something as a checkbox
"Create new layer-Skip undo history" would be sufficiently clear

Anyway i believe that would be against the rules for good scripts and plugin...the first requirement is that whatever is done should be undoable (and my personal interpretation that is what done is create a new layer or a new image, undo is not more strictly needed , may be not approved by others )