Help with importer memory management 2.49

Dear Blender Community,

I have very rudimentary skills in python programming and even more rudimentary skills in the Blender API. Through some help from the Blender community I was able to cobble together this script to create a stop-motion animation.

I wish to display a cluster of UVspheres (and some other things) dynamically changing over time. Becuase there is more than 1 sphere I cannot do motion interpolation so instead I am generating a new sphere for each new frame. With 40 new spheres per frame multiplied by 100 frames makes for a quite a few UVspheres that have to be generated - this is computationally expensive!

When I run this script it often takes around an hour to complete, meanwhile Blender lags.
Is there any way I can free up memory resources during this time?

I am sorry if my description is not very good - please feel free to ask me if you need clarification on what my script does.

Oh by the way, I am running Blender 2.49 on Mac OSX
My script is awfully convoluted - I cannot fit it in this post:
you can find it here: http://cl.ly/12eecbc4265fa077f7f8

Any help with this would be much appreciated.

Thanks,
-ejang