Recovering memory after large volumes of user_load()'s

Sometimes, as in the case of a script which iterates over many thousands of users, loads the user object, manipulates it and then re-saves it, the memory available to the PHP process can become a bottleneck. Unlike in previous versions of Drupal, in Drupal 7 and above users are statically cached after a user_load is performed. If you are sequentially loading thousands of users, you can easily hit up against memory limitations. To force Drupal to release its internal static cache of users after a user_load operation, you can call

resetCache(); ?> Putting this as the last statement in a loop can make all the difference between a script making it to completion or tanking with memory exhaustion.