News for hackers. Stuff that matters.
Re:Coroutines for Go by vaastav on Monday July 17, 2023 @04:16PM (#36763457)
Garbage collector in Go is optional. You can switch off garbage collection by setting the environment variable GOGC=off.

More info about GOGC: https://dave.cheney.net/tag/gogc

Re:Coroutines for Go by gkfasdfasdf on Monday July 17, 2023 @04:22PM (#36763515)
Ok so garbage collection is optional, how about garbage generation? Is there any way to manually clean up resources if GOCG=off, or will memory usage continue to grow unbounded as new objects are created?
Re:Coroutines for Go by vaastav on Monday July 17, 2023 @04:25PM (#36763565)
Grows unbounded. I wasn't recommending that one should set GOGC=off. Just making a remark that one could should they choose to do so.

EDIT: Sorry, I misunderstood part of your question. The memory grows unbounded unless you call runtime.GC() which triggers garbage collection. But this is a blocking call and essentially block your whole program.

Re:Coroutines for Go by Cthulhu_ on Monday July 17, 2023 @04:48PM (#36763859)
I think in theory you can write code (or do some tricks) to avoid all heap allocation.
Re:Coroutines for Go by dgb23 on Monday July 17, 2023 @06:07PM (#36764726)
You mean not growing the heap or literally no allocation?
Re:Coroutines for Go by t8sr on Monday July 17, 2023 @06:13PM (#36764785)
"In theory" being the operative words there. Turn on heap escape analysis sometime, you'll be surprised how hard it is to avoid.
Re:Coroutines for Go by t8sr on Monday July 17, 2023 @06:12PM (#36764771)
Only very theoretically - in Go, you don't control whether memory goes on your stack or the heap, and heap escape analysis is notoriously unpredictable. There is no explicit free. You would have to write Go in a completely crazy way to be able to turn off the GC and have the program not grow unbounded.

You might think "I'll just use static buffers everywhere", but allocations can occur in unexpected places. The compiler does some very basic lifetime analysis to eliminate some obvious cases (loops...), but it's really hard to avoid in general.

Re:Coroutines for Go by kaba0 on Tuesday July 18, 2023 @02:31AM (#36768650)
Well, then so is in Java, with the Epsillon ā€œGCā€. But not collecting garbage is very different than manual memory management.
Re:Coroutines for Go by Tozen on Friday July 21, 2023 @02:21AM (#36810596)
Arguably, one can't truly say the GC is optional, unless the language and its libraries were truly designed to work without it. In languages like Vlang, that's the case, as the GC was a late addition. If turning the GC off cripples the functionality and usefulness of the language, then there is little point in using the option.

Probably a better argument for Go (and other languages like Java) is how "tweakable" the GC is or at least describe it as the GC can be turned off, but it's not designed or useful to do so.