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.
source
share