lua-users home
lua-l archive

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

On Wed, 23 Oct 2002, Nick Trout wrote:
> > What are the
> > caveats to the reference counting scheme David mentioned?
> Cyclic referencing could cause some objects never to be deleted if they
> become isolated. Mark and sweep avoids this problem. Python is reference
> counted and has to have a separate library to find cyclic references.

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?

> It slightly complicates object management from the C side because you
> have to manage the reference count to Lua objects when you want to
> reference them. There is potential for error here if don't reference and
> unreference them correctly. You may be able to hide all of this in the

I think the existing Lua API should be adequate -- a lua_ref just
increments the object's ref count when it's created via lua_ref(), and
decrements it when it's destroyed via lua_unref().  No need to expose
the concept of the ref count outside of the core.