Fixed #4272 and #6237 (Crash from running out of memory with many templates)