# Language Mechanics On Escape Analysis

DevFeed: [Language Mechanics On Escape Analysis](<https://devfeed.tech/articles/language-mechanics-on-escape-analysis-22124.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2017/05/language-mechanics-on-escape-analysis.html>)

Published: 2017-05-26T00:00:00Z

Content type: article

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [escape analysis](<https://devfeed.tech/topics/escape-analysis.md>), [Programming Languages / Compilers](<https://devfeed.tech/topics/programming-languages-compilers.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.md>), [code-analysis](<https://devfeed.tech/tags/code-analysis.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [cpu](<https://devfeed.tech/tags/cpu.md>), [escape-analysis](<https://devfeed.tech/tags/escape-analysis.md>), [gc](<https://devfeed.tech/tags/gc.md>), [go](<https://devfeed.tech/tags/go.md>), [go-programming](<https://devfeed.tech/tags/go-programming.md>), [golang](<https://devfeed.tech/tags/golang.md>), [goroutine](<https://devfeed.tech/tags/goroutine.md>), [heaps](<https://devfeed.tech/tags/heaps.md>), [latency](<https://devfeed.tech/tags/latency.md>), [memory](<https://devfeed.tech/tags/memory.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

The excerpt explains that Go's compiler uses static escape analysis to decide whether a value can live in its function's stack frame or must move to the heap; programmers cannot direct this choice with a keyword or function, but their coding patterns affect it. Stacks clean up as functions return, while heap values require garbage collection. The text says GC uses 25% of available CPU capacity when running and can cause microseconds of stop-the-world latency; more heap values that become unreferenced increase the collector's work. The excerpt begins a discussion of why goroutines cannot point into another goroutine's stack, but cuts off before explaining it.

## Source excerpt

Prelude This is the second post in a four part series that will provide an understanding of the mechanics and design behind pointers, stacks, heaps, escape analysis and value/pointer semantics in Go. This post focuses on heaps and escape analysis. Index of the four part series: Language Mechanics On Stacks And Pointers Language Mechanics On Escape Analysis Language Mechanics On Memory Profiling Design Philosophy On Data And Semantics Introduction In the first post in this four part series, I taught the basics of pointer mechanics by using an example in which a value was shared down a goroutine's stack. What I did not show you is what happens when you share a value up the stack. To understand this, you need to learn about another area of memory where values can live: the "heap". With that knowledge, you can then begin to learn about "escape analysis".