lua-users home
lua-l archive

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


Garbage collection guarantees that unreachable data will be collected at
some point. It does not guarantee when. Garbage collection is a good
fallback for finalization, but if you want immediate finalization, you
should do it yourself.

For example, if we are acquiring and releasing a resource, then we can
create an "object" that handles ownership of the resources on the C/C++
side. We then provide a way for the Lua side to make an explicit "release
this now" call to the object and then wire up the GC finalization for the
object to release it if it hasn't been explicitly released already.

Mark

on 4/25/03 8:03 PM, Bilyk, Alex at ABilyk@maxis.com wrote:

> This example doesn't cut it for me. It is often the case when one can not let
> Lua destroy objects in its own time due to system interdependencies. If system
> A needs system B to manipulate data members of A, clearly, by the time Lua
> decides to collect A, B may have long gone. So, there must be a way to GC
> things on the spot in a fairly straightforward and convenient fashion. What
> about weak keys and values? Could they be of any help to the original poster?
> I have never used them myself.
> 
> Alex