memory safety and prevent unnecessary allocations