Bird
0
0

Examine this code:

medium📝 Predict Output Q4 of 15
Node.js - Debugging and Profiling
Examine this code:
const storedCallbacks = [];
function registerCallback(cb) {
  storedCallbacks.push(cb);
}
registerCallback(() => console.log('Event'));
// storedCallbacks never cleared
What memory problem does this cause?
AStack overflow from recursive calls
BMemory leak due to accumulating unused callback references
CEvent emitter not emitting events
DSyntax error from invalid callback
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the code

    Callbacks are stored indefinitely in an array without removal.
  2. Step 2: Understand impact

    Accumulating references prevent garbage collection, causing memory leaks.
  3. Final Answer:

    Memory leak due to accumulating unused callback references -> Option B
  4. Quick Check:

    Uncleared arrays cause leaks [OK]
Quick Trick: Never keep unused callbacks indefinitely [OK]
Common Mistakes:
  • Confusing memory leak with stack overflow
  • Assuming syntax errors cause leaks
  • Thinking event emission is affected

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes