[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: to-be-closed variables as resources from a library.
- From: Jorge Visca <xxopxe@...>
- Date: Wed, 28 Sep 2022 11:24:40 -0300
On 28/9/22 04:25, Francisco Olarte wrote:
They are just a variation of try/finally, similar to
try-with-resources, not that difficult to understand.
My problem was that in my mind "going out of scope" was "going out of
scope everywhere in the program". Yes I see that that's not how Lua's gc
works.
So, my takeaways (basically derived from what you describe):
* i'll not use <close> variables anywhere i do not have full control of
them or they can leak, nor depend on __close for the system to be correct.
* Conceptually, the main place to release stuff is __gc. Define __close
to call __gc to speed up memory release when the user mind it enough.
* All releasing should be idempotent, always.
* Treat <close> as a memory use optimization, to be used when matters
where it matters.
Thanks for the comments!
Jorge