On this page
What this issue is
Browsers free memory automatically when nothing refers to it any more (this is called garbage collection). A memory leak is when your code accidentally keeps a reference to something, so the browser cannot free it. Each time the user repeats an action, a little more memory piles up.
It matters most on single page apps (SPAs), where the page never fully reloads between views. Multi-step checkouts, configurators, dashboards and chat widgets stay open for a long time, so small leaks add up.
Common causes:
- Event listeners added on every view or render and never removed (
addEventListenerwithoutremoveEventListener) setIntervalorsetTimeoutloops that keep running after the view is gone- DOM elements removed from the page but still referenced in a variable or array (detached DOM nodes)
- Components in React, Vue or Angular that subscribe to a store, socket or observer and never unsubscribe
- Global variables or caches that only ever grow
- Third-party scripts or widgets that re-initialise on every route change
Why it costs you leads or sales
As memory grows, the browser spends more time on garbage collection and the page gets less responsive. Clicks lag, typing stutters and animations drop frames. On phones and older laptops the tab can be reloaded or crash, and the visitor loses their form progress or cart.
The business impact is usually low, because most visitors leave long before a leak matters. It hurts most on long, multi-step journeys, on app-like sites and on low-memory mobile devices, where it shows up as slow interactions late in a session.
Example: a leaking single page app grows with every view the visitor opens, while a healthy one levels off. Numbers are illustrative.
Each view leaves a bit of memory behind until the page lags or crashes.
How to check if your site has it
You need a browser profiler. Use a desktop Chrome window with extensions turned off (an Incognito window works).
Watch memory over time
Open DevTools (F12), go to the Performance tab and tick Memory. Record while you repeat one action 20 to 30 times, such as opening and closing a modal or moving between SPA routes.
Look at the JS heap line
A leak shows as a staircase that keeps climbing. Healthy memory rises and drops back after garbage collection.
Force a cleanup
Click the trash can icon (Collect garbage) in the Memory or Performance tab. If memory stays high afterwards, something is still holding it.
Take heap snapshots
In the Memory tab choose Heap snapshot. Take one, repeat the action 10 times, collect garbage and take a second. Switch the second snapshot to Comparison view and sort by Delta to see which objects keep growing.
Search for detached elements
In a snapshot, type Detached in the class filter. Detached DOM nodes that remain after you leave a view point to leaked references.
Check listeners
In the Performance Monitor panel (More tools menu), watch JS event listeners and DOM Nodes. If either count climbs with each repeat of an action, you have found the leak.
How to fix it
The fix is always the same idea: whatever you set up when a view appears, tear down when it goes away. The exact place depends on your framework or platform.
Leaking
- A new scroll listener is added every time the view renders
- Old listeners keep references to removed elements
- Listener count and DOM nodes climb with each view
Cleaned up
- Listener is removed when the view unmounts
- Timers are cleared and subscriptions cancelled
- Listener count and DOM nodes stay flat
Remove listeners you add
Keep a reference to the handler and call removeEventListener, or pass an AbortController signal so one call removes many listeners.
Clear timers
Store the id from setInterval or setTimeout and call clearInterval or clearTimeout when the view closes.
Drop references to removed elements
Set variables to null or empty arrays and maps that hold removed DOM nodes. Use WeakMap or WeakRef for caches keyed on elements.
Disconnect observers
Call disconnect() on IntersectionObserver, MutationObserver and ResizeObserver, and close WebSocket connections when finished.
Find the offending script
Use the DevTools steps above, then check the Sources tab to see whether the growing code comes from your theme, a plugin or a page builder.
Disable plugins one by one
Deactivate suspect plugins (sliders, popups, live chat, AJAX filters) on a staging copy and re-test. The one that stops the growth is the source.
Update or replace it
Update the plugin or theme, report the leak to the developer with your snapshot comparison, or swap it for a lighter alternative.
Identify the source
Compare heap snapshots on a theme with apps enabled. Check whether the growing objects come from theme.js or an app script.
Test with apps disabled
Duplicate your theme and remove app embeds in the theme editor's App embeds section. Re-test to find the guilty app.
Fix theme code or contact the app developer
In your theme JavaScript, remove listeners and timers when sections are reloaded in the theme editor or replaced by AJAX cart or filter updates.
Check Custom HTML tags
Look for tags that add listeners or intervals. On SPAs, a tag that fires on every History Change can add a new listener each time.
Limit how often they run
Set the tag firing option to Once per page where it makes sense, or guard the code so it only sets up once.
Preview and re-profile
Use Preview mode and repeat the memory test with and without the tag.
const controller = new AbortController();
window.addEventListener('resize', onResize, { signal: controller.signal });
window.addEventListener('scroll', onScroll, { signal: controller.signal });
const timerId = setInterval(refreshPrices, 5000);
function destroyView() {
controller.abort(); // removes both listeners
clearInterval(timerId); // stops the timer
}useEffect(() => {
const onResize = () => setWidth(window.innerWidth);
window.addEventListener('resize', onResize);
const id = setInterval(refreshPrices, 5000);
return () => {
window.removeEventListener('resize', onResize);
clearInterval(id);
};
}, []);How to confirm it's fixed
Repeat the exact action
Do the same 20 to 30 repeats while recording the Performance tab with Memory ticked.
Check the memory line
The JS heap should rise and fall, then settle at a steady level rather than climbing.
Compare snapshots again
Delta counts for the previously growing objects should be near zero, and Detached results should be gone.
Check counts in Performance Monitor
JS event listeners and DOM Nodes should stay flat across repeats.
How to prevent it happening again
- Pair every setup (listener, timer, subscription, observer) with a teardown in the same code review
- Add a memory-growth check to your release routine for SPAs and long flows: repeat key actions 30 times and watch the heap
- Re-test after adding a new plugin, app, widget or tag manager tag
- Use a linter rule for hook dependencies and cleanup in React projects
- Track real user performance, including long-session behaviour, with a real user monitoring tool
- Keep third-party scripts to those you need and update them regularly
How FunnelGuard handles this
This issue is outside what FunnelGuard checks. FunnelGuard runs your customer journeys on a schedule and checks that steps work, tracking hits fire and test leads arrive. It does not profile browser memory over a long session.
The kind of tool that fits is a browser profiler such as Chrome DevTools for diagnosing the leak, plus a real user monitoring (RUM) tool for seeing how slow sessions are for actual visitors. Use FunnelGuard alongside them to confirm your forms, checkouts and tracking still work after you ship a fix. There is a free plan with 1 site and 2 journeys, and a free read-only website audit.
Questions people ask
Why does my website get slower the longer it is open?
Most often the page is leaking memory: event listeners, timers or removed elements are never released, so memory use keeps growing. Record the Performance tab in Chrome DevTools with Memory ticked while you repeat an action and see if the heap climbs.
How do I find a memory leak in JavaScript?
Use Chrome DevTools. Take a heap snapshot, repeat an action about 10 times, collect garbage, take a second snapshot and use Comparison view sorted by Delta. Objects that keep growing, or Detached DOM nodes, point to the leak.
What causes memory leaks in single page apps?
The usual causes are listeners and timers that are not removed when a view changes, subscriptions that are never cancelled, references to removed DOM elements and ever-growing caches or global variables. Third-party widgets that re-initialise on each route change can also do it.
How do I fix a memory leak in React?
Return a cleanup function from useEffect that removes event listeners, clears timers and cancels subscriptions. Then re-profile with heap snapshots to confirm memory levels off.
What is a detached DOM node?
It is an element removed from the page that your code still refers to, so the browser cannot free it. Search for Detached in a Chrome heap snapshot to find them.
Is a memory leak bad for conversions?
It can be, mainly on long journeys, app-like sites and low-memory phones, where the page becomes laggy or crashes late in a session. Most visitors leave before it matters, so the impact is usually low.
Can FunnelGuard detect a memory leak?
No. FunnelGuard checks that journeys, tracking and lead delivery work, not browser memory over time. Use a browser profiler like Chrome DevTools and a real user monitoring tool for this.
Does growing memory always mean a leak?
No. Memory that rises then levels off is normally caching. A leak keeps climbing each time you repeat the same action, even after forcing garbage collection.
Related issues
- PRF-039INP over 200 ms on a CTA or form interactionFix guide
- PRF-040Long tasks over 50 ms block input during loadFix guide
- PRF-041Total Blocking Time high from heavy third-party tagsFix guide
- PRF-044Main thread busy with session-replay scripts (Hotjar, Clarity, FullStory)Fix guide
- PRF-046Multiple versions of jQuery or React loadedFix guide
- PRF-048Scroll jank from scroll listeners / parallaxFix guide