Skip to content
Painter
Deep dives

Memory in a long-lived single page app

The bug report says "it gets slow after a few hours". That is a leak, and the heap snapshot will name it.

Pages that live for hours accumulate what pages that live for minutes never notice: detached DOM nodes held by a closure, listeners nobody removed, an ever-growing cache with no eviction.

Take a heap snapshot, use the app for ten minutes, take another, and compare. The objects that grew are your list, and the retainer path tells you who is holding them.

Detached nodes are the usual answer

An element removed from the document but still referenced by a listener or a closure keeps its whole subtree alive. In a long session that is most of the leak.

Leave a comment

Real questions get real answers. The editorial team reads every thread.