Skip to content

[PERFORMANCE] Memory leak from unremoved event listeners#8

Open
GAURAV-1313 wants to merge 1 commit into
masterfrom
perf/memory-leak
Open

[PERFORMANCE] Memory leak from unremoved event listeners#8
GAURAV-1313 wants to merge 1 commit into
masterfrom
perf/memory-leak

Conversation

@GAURAV-1313

Copy link
Copy Markdown
Owner

Event listeners accumulate in array without cleanup mechanism.

@netlify

netlify Bot commented Jun 24, 2026

Copy link
Copy Markdown

Deploy Preview for nofriction canceled.

Name Link
🔨 Latest commit a324878
🔍 Latest deploy log https://app.netlify.com/projects/nofriction/deploys/6a3c323b9788de0008676c70

@GAURAV-1313

GAURAV-1313 commented Jun 24, 2026

Copy link
Copy Markdown
Owner Author

AI Code Review

Summary

The new event listener attachment code lacks robustness and safety checks, potentially leading to memory leaks and untracked listeners on multiple elements. There is no mechanism for detaching listeners or validating inputs.

Key Findings

Bugs

  • [MEDIUM] attachListeners function — eventListeners array only stores handlers without associating them to elements, making it impossible to remove listeners later — could lead to resource leaks and unintended side effects in long-running applications.
  • [LOW] attachListeners function — No validation on 'element' parameter to ensure it is a valid DOM element, which could cause runtime errors if invalid arguments are passed.
  • [LOW] attachListeners function — No validation on 'handler' parameter to ensure it is a function, risking runtime exceptions if a non-function is passed.

Performance

  • The global array eventListeners grows unbounded with every attachListeners call without removal of handlers, causing memory leak and increased memory consumption over time in long-lived processes.

Recommended Fixes

General

  • Modify eventListeners to store objects with both element and handler references to support proper removal of event listeners to avoid memory leaks.
  • Add input validation in attachListeners to check that 'element' is a valid DOM element and 'handler' is a function, throwing descriptive errors otherwise.
  • Implement a corresponding detachListeners function to remove event listeners and clean up the eventListeners array appropriately.

Performance Fixes

  • The global array eventListeners grows unbounded with every attachListeners call without removal of handlers, causing memory leak and increased memory consumption over time in long-lived processes. — Implement a removal mechanism and avoid unbounded growth by tracking listeners per element and removing them when no longer needed, or use WeakRef-based storage to allow GC.

Auto-Fix Available

Add the apply-ai-fixes label to this pull request to have RepoSpace
automatically generate and commit code fixes for the issues listed above.


4 issues found. Reviewed by RepoSpace AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant