optimize the memory usage.