News for hackers. Stuff that matters.
Re:Go 1.17 Release Notes by throwaway34241 on Monday August 16, 2021 @10:27PM (#28205450)
> Go doesn't even bother providing a means to do this automatically for your non-memory resources when they're garbage collected (Java does, but again, no promises it ever fires, so, don't rely on this).

It sounds like you are talking about finalizers? If so, they exist in Go in a similar way to the Java feature [1].

[1] https://pkg.go.dev/runtime#SetFinalizer

Re:Go 1.17 Release Notes by throwaway894345 on Tuesday August 17, 2021 @08:46AM (#28209246)
Finalizers aren’t quite the same. They run when memory pressure exceeds some threshold, but the GC analog for borrow-checking is something that will clean up a resource when the pressure on the resource in question exceeds some threshold (e.g., file handles). And even then I’m not sure if that ticks all requirements for resource management.
Re:Go 1.17 Release Notes by throwaway34241 on Tuesday August 17, 2021 @04:24PM (#28214438)
I meant to respond only to the quoted section comparing Java and Go, which states that Go doesn't have a way to do cleanup on GC (finalizers). I agree with you (and the two other replies and the quoted section itself) that finalizers are not a replacement for RAII etc.

I don't use them for resource cleanup, but I think they probably make sense for library authors as a back-up mechanism (for example, the standard library has a finalizer to close file handles, and the current runtime does GC every two minutes in the absence of memory pressure). You can also explicitly run the GC in Go, and while generally there's a lot of problems with that idea I could maybe imagine it being viable for certain unusual workloads.

Re:Go 1.17 Release Notes by beltsazar on Monday August 16, 2021 @11:54PM (#28206048)
You usually want to release non-memory resources deterministically, but finalizers in C#/Java/Go are not deterministic. That's why finalizers usually are not used for resource management. Instead, C# has using statements, Java try-with-resources, Go defer statements.
Re:Go 1.17 Release Notes by sagichmal on Monday August 16, 2021 @11:24PM (#28205854)
Finalizers are not guaranteed to run. They're not ersatz destructors.
Re:Go 1.17 Release Notes by throwaway34241 on Monday August 16, 2021 @11:45PM (#28205991)
Yes, if you look at the quote I was responding to, it appears they are saying Go doesn't have finalizers, which is incorrect.
Re:Go 1.17 Release Notes by xpressvideoz on Tuesday August 17, 2021 @02:52AM (#28206935)
Huh, I also thought Go had no concept of finalizers. That is a bit... awkward way to set a finalizer. But thinking it again, it may just be due to my unfamiliarity.