← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
May 2026

Summary

Meta SWE interview with a memory management question that sounds basic until you're actually in the room trying to remember what goes on the heap versus the stack.

Questions Asked (1)

Q1

Walk through the memory changes that happen when you execute: Object o = new Object().

Technical Trade-offsAlgorithms & Data Structures
Author's notes

I knew the general answer but fumbled the sequencing.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the language and runtime (e.g., Java HotSpot) and then walk through the memory changes in chronological order: class loading, object allocation, initialization, and reference assignment. Emphasize the distinction between stack and heap, and mention relevant JVM internals like TLAB and escape analysis.

Pro tip: Mention that the JIT compiler may optimize away the allocation entirely via escape analysis, and that the actual memory layout includes an object header—this shows depth beyond textbook answers.

1. Class Loading and Preparation

Explain that before any object can be created, the JVM must load, link, and initialize the Object class. This involves loading the class file, verifying bytecode, preparing static fields, and resolving symbolic references.

2. Memory Allocation for the Object

Describe how the JVM allocates memory on the heap for the new Object instance. Mention techniques like bump-the-pointer and TLAB (Thread Local Allocation Buffer) for efficient allocation, and note that the object header (mark word and klass pointer) is included.

3. Zeroing and Initialization

Explain that the allocated memory is zeroed out (ensuring all fields have default values) and then the constructor is called. For Object, the constructor does nothing, but the JVM still performs initialization steps.

4. Reference Assignment on the Stack

Describe how the reference variable 'o' is stored on the stack (or in a register) and is assigned the address of the newly created object on the heap. Mention that the reference itself is a pointer-sized value.

5. Potential Optimizations

Discuss how the JIT compiler might eliminate the allocation entirely if the object does not escape (escape analysis), or how it might use scalar replacement to store fields on the stack instead.

Key Points to Mention

  • Stack vs. Heap: reference on stack, object on heap
  • Object header (mark word, klass pointer) and memory layout
  • TLAB and bump-the-pointer allocation
  • Zeroing of memory and default field values
  • Escape analysis and scalar replacement by JIT
  • Garbage collection implications (object becomes eligible when reference goes out of scope)

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.