Creating Custom Events

How do you properly clean up custom event listeners to prevent memory leaks?
class ComponentWithEvents {
  constructor() {
    this.handleEvent = this.handleEvent.bind(this);
    document.addEventListener('customEvent', this.handleEvent);
  }

  destroy() {
    document.removeEventListener('customEvent', this.handleEvent);
  }

  handleEvent(e) {
    console.log('Event handled:', e.detail);
  }
}
Next Question (11/20)