[gclist] ref-counting performance cost

Paul Haahr haahr@jivetech.com
Sat, 2 Sep 2000 13:57:51 -0700 (PDT)


Bill Birch wrote
> [Opinion: Despite the issues with reference counting it remains
> probably the most widely used resource management technique. (COM,
> JavaScript? are some famous examples). It is perhaps a shame that with
> so many of the programmers using it that there isn't better research
> available. ]

If we're counting ad hoc resource management techniques that aren't
built into language runtimes, reference counting is clearly ahead of
mark & sweep, but probably isn't in the lead.

I'd suspect that the most common techniques are:

  - Static deallocation:  Allocate without freeing and reclaim when the
    program exits.  Applies to both statically and dynamically allocated
    resources.

  - Stack allocation:  Allocate on function entry, deallocate on exit.
    Applies to both implicit allocation of local variables and explicit
    allocation and deallocation.

  - Exclusive ownership:  Ensure that each entity is owned by exactly
    one entity and deallocate when the the owner disappears.  This is,
    of course, an implicit reference count of 0 or 1.

I've definitely seen memory, files, and windows dealt with using all
three approaches more frequently than reference counting.  With good
reason:  all three have much better performance than reference counting
and are usually easier to implement correctly, even if they don't apply
to all circumstances.

Region analysis and linear logic are linguistic models that remove the
ad hockery from stack allocation and exclusive ownership.

--p