Reference Count, Don't Garbage Collect

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • Mesh

    A memory allocator that automatically reduces the memory footprint of C/C++ applications.

  • > I've never heard of a reference counting implementation that can handle memory compaction.

    It's possible to add that in theory. But if you are tracing all your memory anyway so you can compact it, you typically might as well collect the garbage, while you are at it.

    But: you are in for a treat, someone implemented compaction for malloc/free. See https://github.com/plasma-umass/Mesh

  • ixy-languages

    A high-speed network driver written in C, Rust, C++, Go, C#, Java, OCaml, Haskell, Swift, Javascript, and Python

  • https://github.com/ixy-languages/ixy-languages

    The real reason why a tracing GC was a failure in Objective-C was due to the interoperability with the underlying C semantics, where anything goes.

    The implementation was never stable enough beyond toy examples.

    Naturally automating the Cocoa release/retain calls made more sense, given the constraints.

    In typical Apple fashion they pivoted into it, gave the algorithm a fancy name, and then in a you're holding it wrong style message, sold their plan B as the best way in the world to manage memory.

    When Swift came around, having the need to easily interop with the Objective-C ecosystem naturally meant to keep the same approach, otherwise they would need the same machinery that .NET uses (RCW/CCW) to interop with COM AddRef/Release.

    What Apple has is excellent marketing.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • c-examples

    Example C code

  • Time to tout my own horn. I made a project comparing different types of garbage collectors (I still prefer the original terminology; both ref-counting and tracing garbage collection collects garbage, so they are both garbage collectors) a few years ago: https://github.com/bjourne/c-examples

    Run ./waf configure build && ./build/tests/collectors/collectors and it will spit out benchmark results. On my machine (Phenom II X6 1090), they are as follows:

        Copying Collector                                8.9

  • mark-sweep

    A simple mark-sweep garbage collector in C

  • To better understand garbage collection, nothing better than implementation. This article is such a joy to read:

    https://journal.stuffwithstuff.com/2013/12/08/babys-first-ga...

  • .NET Runtime

    .NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.

  • It's a "feature" on the language, like others said below.

    The codebase I work with has had many pathological crashes due to this behavior.

    So basically in C# when you use += to subscribe to events, in a big system where lifetimes of objects are independent of each other, you're back to a C/C++ mindset where you should check you have a -= call for the subscribed object when the subscribing object is about to run out of scope. Else you get random crashes, when you get events delivered to an object that should have been dead.

    This is one of the reasons I don't like "event" and += in C#. It's a leaky abstraction, like you said.

    There's WeakEventManager [0] but that's available only in "classic" dotnet framework (and in "new" dotnet but only if you're targeting Windows) since it lives in the WPF namespace. It can be used outside of it, but you still take a dependency on System.Windows.

    There are some other bespoke solutions too.

    There's an open issue on the dotnet repo to add a weak event manager to the standard libs [1]. It's very well worth reading through it, it also has links to the other bespoke solutions available.

    [0] https://docs.microsoft.com/en-us/dotnet/api/system.windows.w...

    [1] https://github.com/dotnet/runtime/issues/18645

  • racket

    The Racket repository

  • Racket has like 5 GC, perhaps more.

    In one extreme you can build Racket using the Senora GC that is conservative and not moving, that is used only for bootstraping.

    On the other extreme, both of the normal versions of Racket have custom moving incremental GC. The docs with some high level explanations are in https://docs.racket-lang.org/reference/garbagecollection.htm...

    The implementation details of the main "CS" version are in https://github.com/racket/racket/blob/master/racket/src/Chez... It's a replacement of the default GC of Chez Scheme that has better support for some features that are used in Racket, but I never have looked so deeply in the details.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts