Skip to content

Silent memory leak #2

Description

@sengardeep

Problem

The LiveTicker component is causing a silent memory leak due to duplicated event listeners (such as window.resize).
Each time the Live Ticker is toggled on and off, a new event listener is attached without removing the previous one, causing memory usage to grow and the app to slow down over time.

Points: 30

Steps to Reproduce

  1. Open the application and navigate to the Live Ticker section.
  2. Toggle the Live Ticker on and off repeatedly.
  3. Use browser dev tools (Performance tab or getEventListeners(window)) to inspect listeners.
  4. Notice:
    • The number of attached event listeners keeps increasing.
    • Performance degrades as more listeners accumulate.
    • Listeners are never removed on unmount or re-render.

Expected Behavior

The component should:

  • Attach event listeners only once, or only when necessary.
  • Properly clean up all listeners in the useEffect cleanup function.
  • Avoid re-attaching listeners on every render or toggle.

Proper example pattern:

useEffect(() => {
  const handleResize = () => { ... };

  window.addEventListener("resize", handleResize);

  return () => {
    window.removeEventListener("resize", handleResize);
  };
}, []);

Activity

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

Metadata

Metadata

Assignees

Labels

Easyeasy issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions