Memory is not freed back to the system until the script ends. However, the memory should be reusable, and 20 MB isn't really that much, so I don't see what the problem is? Is memory use increasing with every iteration of your loop, or do you just not like having your script take up large amounts of memory for its entire run?