lua-users home
lua-l archive

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


I am once again interested in using reference counting either instead of or in addition to Lua's garbage collector. But my reason has nothing to do with speed or responsiveness.

My Lua code often obtains references to COM objects which it doesn't own; that is, it doesn't create these objects, and it shouldn't hold the last reference to them, thus keeping them from being destroyed. Some of these objects correspond to user interface elements, such as windows and controls; these objects implement the IAccessible interface, part of Microsoft Active Accessibility. If such an object has a buggy implementation, then holding a reference to that object after the corresponding UI element has gone away could lead to a crash when the appropriate __gc metamethod finally releases that reference. So reference counting in Lua would ensure that as soon as my code is done with a COM object, its reference to the userdatum wrapping that object is destroyed; at that time, that userdatum's __gc metamethod would be called, releasing the reference to the COM object itself. So reference counting in Lua would lead to greater determinism and easier debugging.

So has anyone implemented a reference counting patch for Lua 5.1? I suppose I could work on it myself, but I haven't studied the Lua core enough to make such a deep change with any confidence.