Don't reuse HashMaps for transaction state if they've grown too big

HashMaps that are big use up a lot of memory and take a long time to clear for
reusing.
Merge pull request #3301 from chrisvest/2.2-recordchanges-close

[2.2] Don't reuse HashMaps for transaction state if they've grown too big