[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: to-be-closed variables as resources from a library.
- From: Michal Kottman <michal.kottman@...>
- Date: Wed, 28 Sep 2022 09:45:22 +0200
I cannot really
recognize, whether local variables are destroyed by gc, or whether
they exist on stack and are destroyed "automatically" and end of their
Variables are not "destroyed by GC", objects in memory (that the variables refer to) are. When the objects in memory (tables, strings, userdata, ...) are no longer accessible from anywhere (e.g. local variables), they are eligible for garbage collection and might be cleaned up at some later point in time, at which point their __gc would be called.
__close is a way to deterministically execute some cleanup when a variable goes out of scope.