Since every call to imagemagick is taking place as a separate process (PHP tells the shell to start imagemagick, imagemagick starts up, processes one image, then shuts down), then there shouldn't be any memory still being used afterwards. If there is, it represents a memory leak in the operating system.
So memory shouldn't be an issue with regards to processing lots of images. Maybe the script is just running out of time (it only gets thirty seconds unless you specify otherwise)?