Optimize memory usage