Manage memory on the server with clearWindow()
masterIn long-running Node.js processes, the internal jsdom window accumulates DOM state, which can lead to memory growth and slowdowns. To prevent this, use clearWindow() to periodically release resources.
Important Notes:
clearWindow()closes the currentjsdomwindow and creates a fresh one.- After calling
clearWindow(), any hooks or configuration set viaaddHookorsetConfigmust be re-applied. - In browser builds,
clearWindow()is a no-op.
import { sanitize, clearWindow } from "isomorphic-dompurify";
// Sanitize as usual
const clean = sanitize(dirtyString);
// Release jsdom resources periodically (e.g., after a request or batch)
clearWindow();