What's the proper way to handle memory leaks with event listeners?
To prevent memory leaks, you should always remove event listeners when they're no longer needed, especially when removing elements from the DOM. Even if an element is removed, its event listeners can keep it in memory if not properly cleaned up. Best practices include: removing listeners in cleanup/unmount functions, using event delegation where appropriate, and keeping track of listener references for removal. Some frameworks handle this automatically, but in vanilla JS it's your responsibility.