How do async methods use stack?

.net, asp.net, async-await, c#

Solution

Every thread you create allocates a complete stack, no matter how little of it you use on that thread. Therefore, creating fewer threads will save memory.

When an async method is waiting for an operation to finish, it saves its state in a compiler-generated object (like a closure for lambda expressions) on the GC-managed heap.

Problem

I just started to use .NET async programming and everyone tells that it's better for server-side code because if I use async keywork ASP.NET won't create threads for every request and will reuse the same threads for all async code. Because every thread needs stack and there may be hundreds of threads, it allows the opportunity to save huge amount of memory, e.g: ``` regular: 1500 threads x 2mb = 3000 mb async: 20 threads x 2mb = 40 mb ``` But does it mean that async code is executing without stack? Or where is it stored and how does .NET use it?

Original source