# 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: tutorial

Language: en

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

Topics: [Go Language](<https://devfeed.tech/topics/go-language.md>), [Static code analysis](<https://devfeed.tech/topics/static-code-analysis.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Code](<https://devfeed.tech/topics/code.md>), [cpu](<https://devfeed.tech/topics/cpu.md>)

Tags: [ardan-labs](<https://devfeed.tech/tags/ardan-labs.md>), [blog](<https://devfeed.tech/tags/blog.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>), [memory](<https://devfeed.tech/tags/memory.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

This tutorial explains heaps and escape analysis in Go. It describes how the compiler uses static code analysis to decide whether values remain on a function's stack or move to the heap, and discusses the resulting garbage-collection costs and possible latency.

## 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".