Assume that there is a function A and A has multiple local variables, and a go procedure B is enabled. B directly uses the local variables of A (call parameters/internal parameters ).
Obviously, each call to a should only involve the internal variable environment of a at that time, or the program will be messy.
This is required in any language, as is go.
However, this poses a problem: After a is executed, the data stack it occupies cannot be released (because the external environment of the open go process needs to be maintained ).
If a occupies a very large stack, it will lead to serious memory waste.
Therefore, the new go program should minimize the dependency on the external environment, especially the reference to the local variables of the external function, the variables used as parameters should be passed to the Go program as much as possible.
In this way, the compiler can perform better optimization by avoiding the go program that depends on the external function environment.
References of the Go program to external variables