Memory in Go

Iman Tung
1 min readMay 16, 2021

A few weeks ago I got opportunities on GoJakarta where I speak about the basic concepts of memory management, pointers, and garbage collector.

In the first part, I give some briefing information on classic stack and heap allocation. Golang already has Escape Analysis and we can use that to check when variables move from stack to heap.

The next part is pointers. I am quite familiar with the pointer concept from C/C++. As far as I know, there is no other popular programming language that has this feature and now it appears again on Golang. I called pointer as god feature which allows us to manipulate memory address (actually it just store memory address and used it :-p). However golang pointer is simpler because we don’t need to deallocate our pointer and no arithmetic support.

Last but not least is the garbage collector (GC). Everyone knows Java GC and wants better GC. Before version 1.5, I still prefer Java GC because of its maturity with many options. But after that, I believe Golang became the winner with its real-time GC. GC latency on golang versions.

  • 300 ms (Go 1.4)
  • 40 ms (Go 1.5)
  • 3 ms (Go 1.6)
  • ~1 ms (Go 1.7)
  • < 100 μs (Go 1.8)
  • < 100 μs even for very large heap (Go 1.9)

Check my full presentation at Slideshare

Previously published in https://imantung.github.io at 12 Dec 2017

--

--

Iman Tung

Technology to write, life to grateful. Overthinking is good, only if it has the output. Fundamental is the main concern.