Skip to content

Exported Blob URLs from URL.createObjectURL are never revoked - memory leak grows with every export in a single session #1705

Description

@anshul23102

Problem

src/lib/ffmpeg.ts creates a Blob URL for the exported video:

return {
  blobUrl: URL.createObjectURL(blob),
  ...
};

URL.createObjectURL creates a reference-counted object in browser memory.
The Blob's memory is not freed until URL.revokeObjectURL is called. The
exportVideo function never calls revokeObjectURL, and there is no cleanup
in the React component that receives the blobUrl.

A user who exports multiple videos in the same browser session accumulates one
unreleased Blob in memory per export. For large video files (100MB+), a few
exports can exhaust available tab memory.

Additionally, the temporary CDN fetch Blob URLs created by toBlobURL for the
WASM core in loadFFmpeg are also created but never revoked.

Impact

  • Memory grows unboundedly with each export.
  • Long editing sessions or repeated exports degrade performance and eventually
    crash the tab.

Suggested Fix

  1. When a new export replaces the previous one, revoke the old Blob URL:
    if (previousBlobUrl) URL.revokeObjectURL(previousBlobUrl);
  2. In the React component, revoke the Blob URL in the cleanup function of
    useEffect when the component unmounts.
  3. Revoke the WASM core Blob URLs after FFmpeg finishes loading (the WASM
    engine retains its own reference to the loaded module; the Blob URL is
    no longer needed after ffmpeg.load() completes).

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions