Whenever you're ready, walk me through how you'd approach this.
Explain the key differences between memory allocated on the stack versus memory allocated on the heap. Compare their allocation and deallocation behavior, lifetime, ownership, typical performance characteristics, and failure modes. Give one concrete code example and explain why the distinction matters in production systems. Scope your answer to general-purpose native or managed runtimes, noting where language or runtime implementation details can change the behavior.