On Sat, 28 Jan 2017 07:05:13 -0800 (PST)
T L <tapir....@gmail.com> wrote:

[...]
> My understanding is finalisers are guaranteed to run for some cases,
> but not for some other cases, for a long running program.
> If any cases are not guaranteed to run, then SetFinalizer would be
> totally useless.
[...]

Many of your posts seem to follow a simple pattern: you posit your own
opinion about some language feature which was created because of
opinion(s) different from yours, and then you try to defend that your
opinion is the only correct one.

If finalizers were indeed totally useless, it would obviously be totally
useless to implement support for them.  Please give the Go devs some
credit in that they are not that incompetent to spend their time on
useless features ;-)  The line of reasoning is indeed this smiple.

Finalizers is a sort of a line of defence which _might_ help prevent
some resource leakage -- or may not, and it's fine: that's what is
called "best effort".

Please consider a type which wraps some resource provided by the
underlying OS.  Let's consider an os.File.  This type might have a
finalizer which would attempt to call the syscall provided by the OS to
close the file handle/descriptor wrapped in a value of that type being
finalized, but still the programmer *is required* to call Close() on
the values of that type after having finished dealing with them.
If the programmer fails to fullfill their obligations, the runtime
might help their program prevent hitting the limit of opened files, but
that'd be a best effort endeavor.

Please note that Go is not unique in this approach: in .NET (which also
features GC'ed runtime), finalizers have the same property: they are not
guaranteed to run, and you have to make sure yourself you properly deal
with objects which need to be cleaned up.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to