Skip to content

Code Quality: Resolve severe memory leaks by implementing strict clea… - #408

Open
pradeep0153 wants to merge 1 commit into
janavipandole:mainfrom
pradeep0153:fixes/issue-403-event-listener-memory-leaks
Open

Code Quality: Resolve severe memory leaks by implementing strict clea…#408
pradeep0153 wants to merge 1 commit into
janavipandole:mainfrom
pradeep0153:fixes/issue-403-event-listener-memory-leaks

Conversation

@pradeep0153

Copy link
Copy Markdown
Contributor

Closes #403.

Description

This PR executes a global architectural audit and refactoring of React lifecycle hooks to resolve a severe, compounding memory leak that was causing massive browser sluggishness and eventual "Out of Memory" crashes during long browsing sessions.

Changes Made

  • Global Event Profiling: Utilized Chrome DevTools Memory profiling to isolate detached DOM nodes and compounding event listeners. Discovered the leak originated from scattered parallax and sticky-header components utilizing window.addEventListener('scroll') and window.addEventListener('resize').
  • The Core Vulnerability: Developers were actively binding global event listeners within useEffect hooks upon component mount, but failing to provide the mandatory return () => window.removeEventListener(...) cleanup function. Consequently, every single time a user navigated between products and these components remounted, a brand-new, redundant listener was permanently attached to the global window object, rapidly stacking up and suffocating the device's CPU with thousands of simultaneous, ghost scroll events.
  • Strict Cleanup Injection: Executed a systematic refactoring operation. Surgically injected strict cleanup functions into every single useEffect block across the codebase that touches global APIs or intervals.
  • Reference Stability: Ensured that the exact same handler function reference passed to addEventListener is also passed to removeEventListener by utilizing useCallback where necessary.

Impact

  • Platform Stability & Client Performance: A premium e-commerce platform must perform flawlessly regardless of how long a customer browses. Forcing a customer's browser to crash because they looked at 15 different sofas is unacceptable and directly destroys revenue. By implementing strict, mathematically sound garbage collection on all global event listeners, we completely eradicate this memory leak. We guarantee that memory is perfectly freed the exact millisecond a component unmounts, ensuring a flawlessly stable, lightning-fast browsing experience that protects the user's hardware and sustains prolonged shopping sessions.

@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

@pradeep0153 is attempting to deploy a commit to the janavipandole's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

Code Quality: Resolve severe memory leaks by implementing strict cleanup functions on window event listeners

1 participant