[whatwg/dom] Proposal: addWeakEventListener (Issue #1396)

bahrus created an issue (whatwg/dom#1396)

### What problem are you trying to solve?

The issue of event listeners causing memory leaks is well known.  Even if the platform does add support for ways to subscribe to elements being disconnected (permanently), it is still a significant developer burden to need to worry about.   Now that we have the concept of weak references to DOM elements, can't we create a weak event listener tied to it?

### What solutions exist today?

Discussed [here](https://dev.to/alex_aslam/how-to-avoid-memory-leaks-in-javascript-event-listeners-4hna, for example.

### How would you solve it?

```JavaScript
oElement.addWeakEventListener(...)
```

or

```
const ref = new WeakRef(oElement);
ref.addEventListener(...)
```

Such solutions exist in other [languages](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/events/weak-event-patterns).

### Anything else?

_No response_

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/1396
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/1396@github.com>

Received on Wednesday, 30 July 2025 22:05:51 UTC