News for hackers. Stuff that matters.
Re:Two years of production Go at CloudFlare by pcwalton on Monday November 11, 2013 @10:13PM (#6715625)
> You don't need finalization functionality in a GC'd language. If you imagine a language that lacks finalization functionality but has automatic memory reclamation, things turn out okay.

Not in fault-tolerant message passing systems, to name just one obvious example. Suppose that you put a bunch of file objects into a buffered channel, and then the goroutine that was supposed to receive those objects panics. Your program wants to recover from panics with recover(). Who closes the file descriptors in those channels? Nobody owns them yet: they were in a channel and the goroutine that was supposed to receive them died.

You might be able to solve this by handing out references to the channel to another goroutine that is supposed to clean up the file descriptors, but this gets really complicated. This sort of thing is why Go is GC'd in the first place. It's much easier to just have the GC clean up the file descriptors in channels in which one endpoint has gone dead, and that's the sort of thing finalizers are for and I assume it's the reason that finalizers were built into Go.

Re:Two years of production Go at CloudFlare by ithkuil on Tuesday November 12, 2013 @07:58AM (#6717476)
one option is for the goroutine to defer a cleanup closure that closes every file in that channel. Panics will cause all deferreds to be called all the way up to the deferred which recover()s.

Another option is to crash the app instead of excessive recover()ing. (obviously there are good reasons to use runtime error handling, but imho fewer than what one would think).

Re:Two years of production Go at CloudFlare by SamReidHughes on Tuesday November 12, 2013 @01:06AM (#6716143)
Have the things in the channel be the equivalent of C#'s IDisposable or something, then the goroutine can clean them up itself.
Re:Two years of production Go at CloudFlare by pjmlp on Tuesday November 12, 2013 @02:40AM (#6716372)
Have you read pcwalton example?

How can the goroutine clean them if it is dead?

Re:Two years of production Go at CloudFlare by SamReidHughes on Tuesday November 12, 2013 @01:46PM (#6719888)
Sorry, the words coming out of my fingers didn't match the thought in my mind. The channel can dispose of them.