Memory cleanup in sql db routines for mass actions.