[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: state of the Lua nation on resource cleanup
- From: Cosmin Apreutesei <cosmin.apreutesei@...>
- Date: Sat, 30 May 2009 02:32:06 +0300
In reply to myself ...maybe the subject is too cold by now... so sorry
for insisting, but I've read all the long thread from February, and I
still don't understand the idea behind the scope finalizers (in all
their incarnations: the "with" syntax, the scoped locals, etc.). What
I don't understand is how can scope exit know that an object should be
finalized? What if it has any other references to it? For instance:
with f = file.open('somefile') do some_global = f end ... should f be
closed by now? what would some_global hold now?
Could someone please get that off my head so I can sleep tonight? Thank you.
On Thu, May 28, 2009 at 13:29, Cosmin Apreutesei
> Hi, sorry I'm late for the party but there's something about the
> scope-exit hook solution (the __exit metametod) that I don't get.
> Aren't the variables (i.e bindings), and not the values (i.e. the
> acquired resources) that get out of scope? Shouldn't finalization
> occur whenever the last reference gets tossed? This would require a
> ref-counting mechanism (eg. like perl), or am I dreaming again?
> Anyway, I think there are two distinct patterns here that need
> distinct approaches: one is RAII, and the other is "catch any errors
> and do something about it". The second is well addressed by pcall() or
> whatever try/catch scheme, but the first is not. IMO, to well address
> RAII in a hi-level garbage collected language, we should free the
> caller of the responsibility of freeing resources it has acquired. In
> such language, there should be no difference (from the RAII pov)
> between acquiring memory for a string and opening a file. That's why
> no try/catch scheme (nor pcall(), which is equivalent in this respect)
> is enough to solve the finalization pattern. So it's the gc that
> should do it, which brings the problem down to gc's non-determinism.
> So my vote goes for a __immediate_gc metamethod implemented via
> ref-counting for determinism. And allow me to hook it from lua! ..do I
> hear an "over my dead body" ? :)