How does the national team golan collector work when compiling?

I am trying to understand how golang garbage collector works when the golang code is compiled, and I think that when using go, run as well. I believe that running goes a little more straight forward and just starts the garbage collector along with the .go files that you use. But is the garbage collector compiled into binary files also when compiled into an executable?

+4
source share
1 answer

Compiled object files do not contain garbage collector code.

When the program starts with go run, the command gowill compile your sources, create and run the executable binary in the temp folder. See below.

When an application is compiled and linked to an executable binary, the executable also includes an executable runtime that loads when the binary starts. This runtime provides the garbage collector among other services, such as runtime display and stack information. This is the main reason why a simple Hello World application is obtained as a 2 MB executable binary.

+9
source

All Articles