TutorialPedia.org
Toggle Menu
Home
Online Go Compiler
Tutorials
JavaScript Tutorials
Golang Tutorials
Linux Command Line Tutorials
Blog
All Posts
Go Memory Management
Review how Go handles memory allocation,garbage collection,and pointers.
1. Which memory area is typically used for short-lived variables with a known size at compile time in Go?
Heap
Stack
Global Memory
Data Segment
2. Which of the following can cause a variable to be allocated on the heap in Go (select all that apply)?
The variable's size is unknown at compile time
The variable is a small integer (e.g., int32)
The variable's pointer escapes the function scope
The variable is a constant
3. Go's garbage collector uses a concurrent mark-and-sweep algorithm with tri-color marking by default.
True
False
4. What term describes the process by which a Go compiler determines if a variable should be allocated on the heap instead of the stack?
5. Which of the following is NOT a responsibility of Go's garbage collector?
Reclaiming memory from unused variables
Preventing stack overflows
Identifying unreachable objects
Minimizing stop-the-world pauses
6. Which of the following are common causes of memory leaks in Go applications (select all that apply)?
Unclosed goroutines holding references to large objects
Orphaned map entries that are never removed
Properly evicted LRU caches
Variables allocated on the stack
7. In Go, a variable declared with the 'new' keyword is always allocated on the heap.
True
False
8. Name the Go tool used to profile memory usage and identify allocation patterns (command-line tool name).
9. Which of the following is a value type in Go, meaning it is passed by value rather than by reference?
Slice
Map
Struct
Channel
10. Which environment variables can be used to tune Go's garbage collection behavior (select all that apply)?
GOGC
GOMEMLIMIT
GOROOT
GOPATH
Reset
Answered 0 of 0 — 0 correct