New answers tagged memory
Extended comment I ran this code several times, with different values for n, and using Map or Do as well as ParallelMap. Each time a plot was created and exported, Mathematica's memory in use increased by about 1.7MB. We can call this a 'leak', but it seems to be by design. So, with n as 1000, and allowing for some memory for the front end and the kernel ...
I think, "Fermat little theorem" can work on your problem. Also, you can find it here
Reported, and forwarded to the developers. It is still there in v9
Top 50 recent answers are included