More cleanup and memory improvements for multi-threaded generation.

Change-Id: I9e4e5c1aa31b37379966b1496394687100812c5f
50 files changed