[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: RFE: refman - adding mention of os.exit not closing variables with default arguments.
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 26 Jun 2020 14:55:46 -0300
> This will release resources such as file handles just fine. The nice thing
> about __close is that it's pretty deterministic, like a C++ destructor, the
> C# using() block, or the Golang "defer" statement. You know when it will be
> called, whereas __gc can be called whenever the VM or a C routine allocates
> memory, so you have to be very careful about touching anything outside of
> the object being garbage collected. The deterministic behavior makes
> __close useful for more than closing file handles and such.
I am not sure I see how calling __close in the cases we are discussing
is different from what you described. Calling __close when exiting a
program is also pretty much "non deterministic", as a program can call
os.exit anywhere. Moreover, there is no intrinsic order we could use to
close coroutines, so all these objects being closed together should also
be careful about what has been closed already. Dead coroutines pose
similar problems.
Probably it is not by chance that C++ does not call destructors for
objects in the stack when os.exit is called.
-- Roberto