Odin Arena Allocators and Dynamic Arrays: Hidden Pitfalls

Using arena allocators with dynamic arrays in Odin presents subtle pitfalls. Arenas efficiently manage allocations with the same lifetime, deallocating everything at once. However, dynamic arrays' growth mechanism leaves old memory blocks unfreed when using an arena allocator, leading to wasted memory. The article explains why: arena allocators don't support individual deallocations, and dynamic array growth creates a 'graveyard' of old blocks. Solutions include using the default allocator, pre-allocating maximum size, or employing a virtual growing arena. While the virtual growing arena prevents memory block movement, it's not immune to potential waste. The article concludes that if memory usage is highly dynamic, avoiding arena allocators is advisable.