Optimizing garbage collection