Cherry pick in the fix for threads not free'ing their memory when they scale back down. TRQ-2498.