Close all temporary tables which have not been used any more

This change can reduce memory usage.