Top 11 Memory Interview Questions
Browse 11 real-world technical and behavioral interview questions about Memory. Review scenarios, edge cases, and architectural best practices.
You read a four gigabyte CSV into pandas and the process needs far more memory than that. Where did it go?
Object-dtype string columns hold pointers to individual Python objects rather than packed bytes, any missing value promotes an integer column to float64, and the parser's peak exceeds the final frame. Declare dtypes, select columns, use categoricals, and prefer a columnar file.
How does the .NET garbage collector decide what to collect, and how would you make a hot path allocate less?
The GC segregates the heap into generations on the assumption that most objects die young, collecting gen0 often and gen2 rarely, with large objects on a separate heap that is not compacted by default. Allocating less means removing boxing and using Span<T> over pooled or stack memory.
Your .NET service keeps getting OOM-killed in its container while the GC reports a small heap. Where has the memory gone?
The kernel kills you on everything in the cgroup, while the GC only reports the managed heap. Committed-but-empty heap, per-core Server GC heaps, thread stacks, native buffers and loaded code all count against the limit and none of them appear in a heap size figure.
How would you rewrite a row-by-row pandas transformation, and what is SettingWithCopyWarning telling you?
Push the work into a whole-column operation so the interpreter is entered once instead of once per row, replace chained indexing with a single .loc assignment, and move to DuckDB, Polars or a cluster once the frame plus its intermediate copies stop fitting in memory.
A hot path allocates heavily and garbage collection is showing up in your profile. What does Span give you that a substring does not?
Span is a stack-only view over memory you already have, so slicing it costs nothing while Substring allocates a new string and copies. It removes allocations rather than making them faster, which is the right lever in a runtime where the cost is collection pressure rather than the allocation itself.
Why would you stream a large file rather than read it into memory, and what is backpressure?
Node.js stream backpressure prevents a fast producer from filling memory while a slow consumer catches up. The core signal is write() returning false and the producer waiting for drain before sending more.
Memory keeps climbing in a Go service under load. How do you find out why, and what can you actually tune?
Take a heap profile and compare two taken minutes apart, because the shape of the growth tells you whether it is a leak, a cache with no bound, or simply the collector letting the heap grow. The two real knobs are GOGC and GOMEMLIMIT, and reducing allocation matters more in Go than in a generational runtime.
What is the difference between a value type and a reference type in C#, and what do nullable reference types guarantee?
C# value types store data directly and copy on assignment, while reference types store references to heap objects. Nullable reference types are compile-time flow-analysis warnings, not runtime null guarantees. It also connects structs to the point an interviewer is testing.
What happens when you append to a slice, and when do two slices stop sharing memory?
Go slice append either extends the existing backing array or allocates a new one when capacity is exhausted. Bugs appear when two slices share the same array and one append mutates data the other still observes.
How do generators reduce memory use, and when are they the wrong choice?
A generator produces items on demand and keeps only the current item plus its suspended frame, so memory stays flat as the input grows; it is the wrong tool when you need a length, indexing, or more than one pass, and when per-item resume overhead outweighs the space saved.
A long-running Python service keeps climbing in memory and never comes back down. How do you work out where the memory went?
CPython frees an object the instant its reference count reaches zero, so steady growth is usually something still holding a reference rather than a leak. The cycle collector reclaims only reference cycles. Measure with tracemalloc first, then use __slots__ or generators to cut per-object and peak cost.