Exercise 2: Why the Cleanup Function's Track-Stopping Line Matters — Possible Solution ==================================================================== WHAT HAPPENS IF THAT LINE IS OMITTED ------------------------------ Without stream?.getTracks().forEach(track => track.stop()) in the cleanup function, the camera stream keeps running even after the component that started it unmounts. A getUserMedia stream isn't automatically released just because the React component that requested it is gone — something has to explicitly call stop() on each track, and the cleanup function returned from useEffect is the only place that happens. WHY THIS MATTERS SPECIFICALLY FOR A SCAN SCREEN ------------------------------ A scan screen is exactly the kind of component a user navigates to and away from repeatedly — scan an item, go back, scan another one later. Each mount without a matching cleanup leaves one more orphaned camera stream running in the background. Beyond draining battery and leaving the camera's "in use" indicator lit when it shouldn't be, repeated visits can eventually hit the browser's own limit on simultaneous open camera streams, causing a later getUserMedia call to fail for reasons that would look confusing without knowing about the leaked streams underneath. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains that a camera stream isn't automatically released on unmount and requires an explicit stop() call, and it correctly ties that specifically to a scan screen's own repeated mount/unmount pattern, naming concrete consequences rather than a vague "it's bad practice" statement.