lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I've been thinking about this a little -- the regular mark-sweep
> should be able to collect cyclic stuff, right?  So
reference-counting
> is sort of an incremental collector for non-cyclic structures.  The
> great thing about reference counting is that it's simple and easy to
> understand.  Has David posted his patch publically?

Reference counting is not "incremental" in any interesting
sense: there is no bound on the number of blocks freed by any single
assignment.  In fact, the same is true even for completely manual
storage management: calling "free" is not a constant time operation,
so even if you move to more complicated reference counting schemes,
you still lose.

I really don't understand this infatuation with reference counting:
it's inefficient on the average, it does not guarantee bounded
latency, and it leaks storage in the presence of circular structures.
 Implementing it right is a lot of work and it infects every single
piece of C code with error prone operations.  And, unlike garbage
collection, where you have to worry about GC pauses only when you
allocate something new, reference counting may hit you with memory
management pauses on any assignment.

If you want soft or hard real-time response for dynamic memory
allocation, well-implemented garbage collectors are not only
convenient, they are pretty much your only choice.  Anything else may
appear to work most of the time, but it doesn't guarantee anything.
It would be great for Lua to get a real-time or soft real-time or
incremental GC.  Until then, paying a little attention to when you
allocate storage, using storage pools, and invoking the garbage
collector frequently when your process is idle probably will work just
as well as reference counting, if not better.

Tom.