Unofficial Hacker News companion — get notified on comment replies, and more.

The state of Rust allocators in 2026: stabilised (opens external site)

217 points by fanf2 3 days ago | cetra3.github.io | 90 comments on HN | Vote on HN (opens Hacker News) |

View full thread · View on Hacker News

Comment thread (3)

  1. > Instead, what if we knew that we would have a period of time in our code, where we're going to allocate a lot of stuff, do something with it, and then free everything? A good example of this is a web request, or a database query.

    > A request comes in, fills in some data structures, and then when the request finishes, the memory isn't needed anymore so it's dropped. This sort of "burst" pattern of allocation, where you allocate a lot up front, and then tear things down all at once at the end, is quite common.

    FYI: Generational garbage collectors, such as the one used in the dotnet framework since the beginning (~2002), are very good at handling this.

    Basically, the 0 generation starts as a large chunk of memory, and before a slow "mark and sweep" the reachable objects that are in the 0 generation are copied to the 1 generation. This implicitly deallocates unreachable objects in the 0 generation.

    (Then again, there are a lot of tradeoffs to using a garbage collected language vs. Rust. I find that a program in Rust, vs an equivalent in C#, has a significantly lower RAM footprint.)

    Replies (1)
    1. I wrote a blog post about this connection a while back: https://steveklabnik.com/writing/borrow-checking-escape-anal...
      Replies (1)
      1. In practice, "garbage collected" means a tracing garbage collector, as opposed to other automatic memory management systems. IE, When Objective C added automatic reference counting, they didn't call it "garbage collection" because you still had to manage cyclic loops; and because "garbage collection" was a deprecated option for an experimental tracing GC. They called it "automatic reference counting" because, in practice, garbage collection means a tracing garbage collector. (The best reference I can find on this is https://stackoverflow.com/a/6385904)

        I also would never call Rust a garbage collected language. It's more like a language where the compiler enforces memory safety. The difference is that it's on the programmer (or AI) to write correct code; and correct code includes implicit deallocations; but you still need to manage cyclic loops in RC or ARC.