Memory
27 bites tagged Memory — interview questions with model answers, and 60-second explainers.
How react-native-screens optimizes a deep stack
React-native-screens uses native container views so off-screen screens are detached from the view hierarchy and can be freed; enabled by default and powers the native-stack navigator. native screen optimization.
Streaming large file downloads efficiently
Use StreamingResponse with a generator that yields chunks (or FileResponse for an on-disk file), set media_type and a Content-Disposition header, so memory stays flat regardless of file size. Memory-safe file delivery.
V8 generational GC and event loop responsiveness
Young-generation scavenges are frequent but short, old-generation major GC is rarer but longer, stop-the-world pauses block the single JS thread. how GC pauses affect Node latency.
What is a Node.js Stream and why use one
A stream processes data in chunks over time, so memory stays bounded and work starts before all data arrives; ideal for large files and network IO. Understanding chunked processing and memory efficiency.
Counting lines in a 5GB log file efficiently
ReadFile loads all 5GB into RAM and may exceed buffer limits, instead stream with createReadStream plus readline and count line by line. streaming versus buffering large data. proposing readFile then split on newlines.
Designing an autonomous research-and-report agent
Planner that decomposes goals, short-term scratchpad plus long-term vector memory, structured tool calls, and a reflect-retry loop for error correction. Agent architecture fundamentals.
What memory problem PagedAttention solves
Pre-allocating contiguous max-length cache per sequence wastes memory through internal and external fragmentation; PagedAttention stores KV in fixed non-contiguous blocks like OS paging. KV-cache memory management at serving scale.
Diagnosing high Redis eviction and cache misses
Use INFO memory and stats to confirm pressure, check fragmentation ratio, pick LFU over LRU for skewed access, set sane TTLs. practical Redis memory debugging. just raising maxmemory without finding the cause.
How does a hash join handle memory overflow?
The build table is partitioned by hash and spilled to disk, then probe rows are partitioned the same way, and pairs are joined per partition. understanding of query execution under memory pressure.
Retain cycles and how to break them
A cycle is two objects (or a closure and its owner) holding mutual strong references so neither deallocates; break it with a [weak] or [unowned] capture list. ARC and closure capture.
Faulting in Core Data
A fault is a placeholder object whose property data is not yet loaded; accessing a property fires the fault and fetches from the store, saving memory. lazy loading in Core Data. ignoring the N+1 fetch storm faulting can cause.
Copy-on-write and implementing it for a custom struct
CoW shares a buffer until mutation, deep-copying only when the buffer is non-unique; Array, Dictionary, Set, String use it; implement with a class storage box and isKnownUniquelyReferenced. value semantics with shared backing storage.
Debugging a closure capture leak in a third-party library
Use the Memory Graph Debugger to inspect retain paths, the Leaks and Allocations instruments, and malloc stack logging; trace the cycle before patching. methodical leak diagnosis.
Verifying and avoiding copy-on-write overhead
Confirm extra copies via isKnownUniquelyReferenced or instruments and the retain trace; ensure unique references, mutate inout/in place, reserveCapacity, avoid aliasing. CoW mechanics and mutation patterns.
What an autoreleasepool is and when to add one manually
An autorelease pool holds objects until it drains; wrap tight loops creating many temporary ObjC objects in autoreleasepool to cap peak memory. deferred deallocation under tight loops. thinking it relates to ARC retain cycles.
Struct versus class performance and memory tradeoffs
Structs are value types, often stack-allocated with no ARC; classes are heap-allocated reference types with retain counts. value versus reference semantics and allocation cost. claiming structs are always faster.
Go slices versus Rust Vec growth and reallocation
Both are a (pointer, length, capacity) triple over a heap buffer that reallocates and copies on growth, roughly doubling; key difference is Go slices share backing arrays and have no ownership… understanding of dynamic-array internals.
Swift Basic Types: Value Semantics by Default
Swift's basic types are value type structs, so assignment copies, not shares, a reference. You feel this when passing Strings into functions or choosing Int over Double. The footgun is treating them as free to copy; large values cost memory and speed.
Compare Go's []byte and Rust's &[u8]
Tests memory-model depth: Go slices are GC-managed headers (ptr, len, cap) permitting shared mutation, while Rust &[u8] is a borrow-checked fat pointer (ptr, len) enforcing aliasing-XOR-mutation.
Static dispatch with impl Trait versus dynamic dispatch with Box<dyn Trait>
Tests monomorphization versus vtables. Note: static dispatch monomorphizes for zero-cost abstraction but bloats code; dynamic dispatch uses vtables for smaller binaries but adds indirection.
How does struct field ordering affect memory layout in Go and Rust?
It tests alignment, padding, and compiler layout knowledge. A strong answer explains that alignment inserts padding, Go and Rust keep declared order, and reordering by size can shrink size. Red flag: saying order is irrelevant or that compiler auto-packs.
Define a User struct and map of IDs to pointers
Tests Go struct and map pointer basics. Outline: define User with ID and Name, initialize map[int]*User with make, insert &User literals, and note shared mutation. Red flag: writing to a nil map or storing values instead of pointers.
Explain generational GC in ART and why onDraw must avoid allocations
Covers young-gen nursery, mark-sweep fallback, and why a 5-10ms GC pause misses 16ms frame deadline. ART generational GC and onDraw allocation hazards. Blaming GC without linking allocation to frame timing.
Heap Snapshots: Finding Node.js Memory Leaks
A heap snapshot is a photograph of your app's memory. Use it to diagnose leaks by comparing snapshots over time to see which objects grow. The big footgun: taking one freezes your app and can double memory usage, risking a crash in production.
Get Memory bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.