lua-users home
lua-l archive

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


Sure, Mark, this is probably the cleanest and most reliable way to release C objects. I don't think it is possible in Lua to release an object "at will" as there is no way to predict if there are any other outstanding references to any given object.

Alex.

 -----Original Message-----
From: 	Mark Hamburg [mailto:mhamburg@adobe.com] 
Sent:	Saturday, April 26, 2003 9:55 AM
To:	Multiple recipients of list
Subject:	Re: tables and the gc

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