• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by John Dev


30 Nov, 2024

Updated at 05 Dec, 2024

Making Arenas Memory-Safe Via New Standard Trait?

Starting to learn about and applying more advanced Rust patterns I discovered arenas, specialized memory allocators that allow you to batch deallocation of objects with similar lifetimes.

One issue however I've been encountering using popular arena creates like bumpalo is the fact that if you're not careful it's quite easy to leak memory with these libraries.

This is because a big part of the savings when it comes to using arenas is the idea that you don't need to individually drop objects anymore, the arena drops everything at once without running each object's drop implementation.

This is a problem for types like Vec, String, etc. that manage their own heap allocation. Skipping drop leaks memory.

However if there was some trait like HandlesOwnHeap or RequiresDrop for Vec then e.g. bumpalo's Bump arena could have a trait bound on its alloc method that prevents you from accidentally using it with such a struct.

2 posts - 2 participants

Read full topic