Go

Memory, GC & Runtime Internals Interview Questions

38 Go interview questions on memory, gc & runtime internals, with detailed answers and code.

0/577 known
38 questions
Memory, GC & Runtime InternalsQ333Hard

Returning or storing its address somewhere that outlives the frame: a global, a heap object, or a channel send of a pointer. Interface conversion , where a non-pointer…

Memory, GC & Runtime InternalsQ337Hard

A write barrier is a small piece of code the compiler inserts around pointer writes into heap memory . It runs only while the GC is marking; otherwise it is skipped by a…

Memory, GC & Runtime InternalsQ342Medium

gc 14 @2.104s 3%: 0.021+4.1+0.034 ms clock, 0.17+1.2/7.9/15+0.27 ms cpu, 48->52->21 MB, 50 MB goal, 0 MB stacks, 0 MB globals, 8 P gc 14 @2.104s 3% : the 14th cycle, 2.1…

Memory, GC & Runtime InternalsQ345Hard

sync.Pool is a concurrency-safe cache of temporary, interchangeable objects. Each P has its own local shard, so Get and Put take no lock in the common case. Objects can…

Memory, GC & Runtime InternalsQ346Medium

In benchmarks, call b.ReportAllocs() or run with -benchmem to get B/op and allocs/op . Since Go 1.24, prefer b.Loop() . It resets the timer automatically and keeps the…

Memory, GC & Runtime InternalsQ348Medium

package main import ( "fmt" "unsafe" ) type A struct { a bool b int64 c bool } type B struct { b int64 a bool c bool } func main() { fmt.Println(unsafe.Sizeof(A{}),…

Memory, GC & Runtime InternalsQ351Hard

The unsafe package documents six valid patterns. Everything else is invalid, even if it happens to work today: Convert *T1 to unsafe.Pointer to *T2 , when T2 is no…

Memory, GC & Runtime InternalsQ357Hard

The GC decides liveness from the point of last use , not from lexical scope. An object can therefore become unreachable, and its finalizer or cleanup can run, in the…

Memory, GC & Runtime InternalsQ363Medium

import _ "net/http/pprof" // registers /debug/pprof/* on DefaultServeMux func main() { go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() // ... }…

Next topicPerformance, Profiling & Testing