• Ethan@programming.dev
    link
    fedilink
    English
    arrow-up
    1
    ·
    9 hours ago

    Garbage collection is analyzing the heap and figuring out what can be collected. Reference counting requires the code to increment or decrement a counter and frees memory when the counter hits zero. They’re fundamentally different approaches. Also reference counting isn’t necessarily automatic, Objective-C had manual reference counting since day one.

    • BatmanAoD@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      5 hours ago

      “Garbage collection” is ambiguous, actually; reference counting is traditionally considered a kind of “garbage collection”. The type you’re thinking of is called “tracing garbage collection,” but the term “garbage collection” is often used to specifically mean “tracing garbage collection.”

    • CanadaPlus@lemmy.sdf.org
      link
      fedilink
      arrow-up
      2
      ·
      7 hours ago

      It’s still mentioned as one of the main approaches to garbage collection in the garbage collection Wikipedia article.