Memory and event listener cleanup

What should happen when the view closes?

Examples

Worked example

Input
A view registers a resize callback each time it opens.
Expected output
Remove that view’s resize callback.

Hints and solution

Hint 1

Write down the starting state and walk through one example by hand.

Reveal worked answer

Window can outlive the view. Removing the listener prevents extra callbacks and releases objects kept alive only through that listener.

Back to the lesson