Reference counting

We came to the conclusion today that the world would be a little bit better if anyone who suggested using reference counting instead of a real garbage collector could receive a small non-lethal electric shock.

You can implement a real GC in only 600 lines of code or so. It’s not that hard people.

About these ads

4 Comments

Filed under Uncategorized

4 responses to “Reference counting

  1. You can in a sane language, but if you program in a sucky language like C++ you can’t.

  2. Reference counting is certainly slower, and has worse locality of reference than “real” GC. However, it does have the virtue of releasing objects as soon as possible (when combined with “real” GC to collect cycles). This is a good fit for interpreted languages (like C python) where the slowness is tiny compared with the interpreter overhead.

    • rich

      Except when it doesn’t release objects because of circular references. This was indeed our problem yesterday — combining closures and reference counting [in Perl] makes it virtually impossible to avoid cycles.

      There was a second part to this electic shock theory: people suggesting interpreters instead of writing a good compiler. With LLVM (or even without) there is really no good excuse any more to be writing slow interpreters.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s