TRAP ACTIVE

JS 2D Matrix Trap & Memory Inspector

Creation Pattern Select strategy

Live In-Memory Matrix Click cell to mutate

Target: [0][0]
V8 Heap Identity Assertions
matrix[0] === matrix[1] true
matrix[1] === matrix[2] true
Are rows independent allocations? NO (SHARED REF)

V8 Heap Inspector Memory Layout

ALLOCATED HEAP OBJECTS
EXECUTION TELEMETRY
Total Heap Allocations: 1 Array Buffer
Row Pointer References: 3 referencing #0x7F10
Sparse Array Holes: 0 holes
Estimated Memory Overhead: ~120 bytes
CPU Cache Locality: Pointer Chasing (Poor)
Uber Interview Golden Answer: "Use Array.from({length: m}, () => new Array(n).fill(0)). The callback runs once per row to allocate distinct arrays. The inner fill(0) is safe because 0 is a primitive value copied by value, not reference."

Separate row references from allocated matrix storage

Read the explanation

The default three-row fill pattern constructs one inner array, then fills three outer slots with its reference. The initial write of nine at row zero column zero therefore appears in all three rows. Bars show three changed displayed cells versus one under a fresh-array-per-row factory, at one hundred fifty pixels each. The same reference explains the effect; the displayed hexadecimal addresses are teaching labels, not measured engine addresses. Array from calls its factory once per outer index, creating three distinct rows for the default height. By contrast, mapping a new sparse array skips all three empty slots and invokes no row factory. Bars use one hundred fifty pixels per callback. Spreading the sparse array first materializes values so map can run. These are written JavaScript array operations, not timing or memory-overhead benchmarks. A three by four Float sixty-four array stores twelve elements in one buffer. Row-major indexing maps row two column three to two times four plus three, index eleven, the twelfth slot. Bars show twelve element slots versus four columns at forty pixels per slot. Rows and columns remain a view over the contiguous buffer. Claims about cache efficiency in the page are illustrative; no physical hardware timings are measured.

Super generates helpful tools and automates fact-checking across the internet proactively. If you enjoyed this tool, build your own with Super and share it with a friend.