Skip to content

Commit 213084f

Browse files
fix: explain the empty RAM view
A small int, bool, or None lives directly in the stack frame, so x = 1 allocates nothing on the heap and the RAM tab looked blank. Say so instead: the RAM view lists heap objects, point to the Memory tab for the value, and suggest xs = [1, 2] or w = 'hi' to watch a row appear.
1 parent 2ee6797 commit 213084f

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/ui/memory.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,19 @@ export function renderRam(svg: SVGSVGElement, state: MemoryState, liveIds: strin
455455
addText(svg, COL_REF, 18, 'REFC', COLORS.muted, 10, 'start', 'middle', mono);
456456
addText(svg, COL_VALUE, 18, 'VALUE', COLORS.muted, 10, 'start', 'middle', mono);
457457

458+
// Empty-state: nothing allocated on the heap yet. Small numbers, booleans,
459+
// and None live directly in the stack frame, so `x = 1` shows nothing here —
460+
// a beginner needs to know that's expected, not a bug.
461+
if (ids.length === 0) {
462+
addText(svg, HEADER_X, 70, 'Nothing on the heap yet.', COLORS.ink, 14, 'start', 'middle');
463+
addText(svg, HEADER_X, 94, 'The RAM view lists the objects Python has to allocate memory for — lists,', COLORS.muted, 11, 'start', 'middle', mono);
464+
addText(svg, HEADER_X, 112, 'strings, dicts, and the data behind numpy/pandas. Small numbers, True/False,', COLORS.muted, 11, 'start', 'middle', mono);
465+
addText(svg, HEADER_X, 130, 'and None are kept right in the stack frame, so `x = 1` won\'t appear here.', COLORS.muted, 11, 'start', 'middle', mono);
466+
addText(svg, HEADER_X, 158, 'Find `x` on the Memory tab (in the <module> frame).', COLORS.muted, 11, 'start', 'middle', mono);
467+
addText(svg, HEADER_X, 180, 'Try xs = [1, 2] or w = \'hi\' and watch a row appear below.', COLORS.amber, 12, 'start', 'middle', mono);
468+
return;
469+
}
470+
458471
let y = 34;
459472
for (const id of ids) {
460473
const obj = state.heap[id]!;

0 commit comments

Comments
 (0)