New javascript dev, and only started dipping my toes into the webdev world.
I feel like I’m getting gaslit by chrome dev tools or I’m misunderstanding completely how removeEventListener works.
Is this a known issue or have i done something wrong?
What i’ve done is click 5~6 times and then press the collect garbage button (broom icon) next to memory which results in a saw like pattern. But the net number of event listener’s keeps increasing.
Here’s the code I’ve used to produce this.
<!doctype html>
<html>
<head>
<script>
function handleClick(e) {
console.log("click");
document.removeEventListener("click", handleClick);
document.addEventListener("click", handleClick);
}
document.addEventListener("click", handleClick);
</script>
</head>
<body></body>
</html>
There are 2 other instances in stack overflow reporting similar things but neither of them seem properly answered.
JavaScript listeners keep increasing
Listeners in Chrome dev tools’ performance profiling results