[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Garbage collection
- From: "Nick Trout" <ntrout@...>
- Date: Wed, 23 Oct 2002 17:24:06 -0700
> [mailto:owner-lua-l@tecgraf.puc-rio.br] On Behalf Of Thatcher Ulrich
> Sent: Wednesday, October 23, 2002 4:23 PM
> 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?
If the patch is public then I don't know where it is.
Maybe you could use the two together. Python has had to resort to this.
I believe their cyclic collector is a script library so Lua would have
the advantage of a faster C based one. I've no idea what algorithm they
use but I don't think its mark and sweep.
http://www.python.org/doc/current/lib/module-gc.html
> > 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.
I havent had time to check and I don't know if there are differences in
Lua 5, but from what I remember you could use ref and unref as you
describe. I don't think you'd have to alter their functionality as they
are reference counting/locking Lua objects already. The internals of Lua
would, I think, need some work. So this patch will be interesting to
see.
You may get problems when you get "islands" of objects which the M&S
collector would delete but have C references to and should not be
deleted. Lua_ref() locks these objects for C. There may have to be a
separate counter for Lua internally which the C count would override.
A (total) reference count method to return the number of references to
an object would still be a very useful debugging tool for making sure
that you are releasing objects when you think you are. (eg. When you do
a obj=nil).
Nick