On Tue, Dec 7, 2021 at 6:20 PM Kurnia D Win <kurnia.d....@gmail.com> wrote:

> Why runtime force gc every 2 minutes?,
> https://github.com/golang/go/blob/016e6ebb4264f4b46e505bb404953cdb410f63f2/src/runtime/proc.go#L5226
>

It's a heuristic. The Go developers probably observed that starting a GC
approximately every two minutes was a reasonable trade-off between the
overhead of a GC cycle and memory used.


> AFAIK gc will be triggered when user try to allocate memory (the mallocgc
> func)
>

Not true.


> and if user want to force gc every 2 minutes, they can create their own
> goroutine to call runtime.GC() every 2 minute
>
> Requiring that level of control is generally anathema to a GC language.
The language runtime should provide reasonable behavior for the vast
majority of its users without requiring them to manually jump through such
hoops. What you're suggesting is equivalent to saying that Go should
require its users to manually manage its memory; such as with `C`.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CABx2%3DD-u5BrepwzqtG6Ag-QBfXbCb0S-odFCH%2Bh-RYv%3DzBn%2BfA%40mail.gmail.com.

Reply via email to