20
In Golang saw that this language is compiled (and indeed, the website itself tells for which architectures the compilers generate code), and, to my surprise, is Garbage Collected!
Garbage Collection is virtually universal in the world of VM and interpreted languages.
And the implementation of these garbage collection algorithms is obvious: The interpreter/VM implements algorithms for collecting allocated memory; this is possible because the execution of the program lies within the execution of another independent program that takes care of memory.
But in a compiled language, the program is "loose": It runs independently.
So without a Runtime wrapper, how Golang implements Garbage Collection?
Edit 1
Well, roughly speaking, what I understood from the answers was:
Go does not have a Runtime for Garbage Collection, but has a "companion" Runtime: GC is implemented as a standard language implementation library. Every program written and compiled in Go runs independently, but next to it there is another Runtime for memory.
I don’t have much authority over it, so I won’t answer, but there’s no secret. If an allocation fails, the GC is invoked. In a way the GC is only a part of the lib (this is a simplification), and will know what to do. Eventually it is possible to fire the GC at other times, but it is not very common. If it is called at other times, it is the most common techniques are: at specific events like timer or some other action that makes sense or even manual calls to GC in algorithms that make sense your call. But I doubt it goes beyond the memory allocation that fires it. Iofc in VM.
– Maniero
Nor am I an expert on Go, but I read two texts with very interesting and related information about both GC and memory management in general: Link 1: http://blog.cloudflare.com/recycling-memory-buffers-in-go Link 2: http://stackoverflow.com/questions/7823725/what-Kind-of-Garbage-Collection-does-go-use
– Marcelo Bezerra bovino
You can have a look at: http://code.google.com/p/go/source/browse/src/pkg/runtime/mgc0.c
– Victor Martins
It is interesting to note that starting with version 1.5, the GC of Go runs together with the other goroutines of the Runtime, and for a maximum of 10ms every 40ms. It was a considerable performance increase compared to previous implementations.
– thepanuto