[Feature Request]: Release previously emitted files via this.emitFile
What problem does this feature solve?
Files emitted via this.emitFile are currently kept in memory for the lifetime of the process, and there is no way to release them. This leaks memory in long-running build --watch (and Full Bundle Mode / bundled dev) sessions — especially when a large asset is emitted and then modified many times.
The concrete cases (from the Rollup counterpart rollup#6095), using the common asset pattern where foo.js contains new URL('./bar.png', import.meta.url), a plugin emits bar.png via this.emitFile in the transform hook, and calls this.addWatchFile('./bar.png') so transform re-runs when the asset changes:
- The emitting module's asset is updated — the user edits
bar.png; becauseaddWatchFilewas called,transformre-runs and callsthis.emitFileagain with the new content. Both the old and the new content ofbar.pngnow live in memory. - The emitting module's asset is deleted — the user deletes
bar.png;transformre-runs, but the old content ofbar.pngstill lives in memory.
Rollup has the exact same problem (filesByReferenceId holds emitted assets indefinitely), which is why rollup#6095 was filed — and it was filed from Rolldown work, explicitly to align the two bundlers. So this is both a memory-safety fix and a Rollup-parity item.
Vite impact: this is the #10019 §6 (Memory safety) checklist item for Full Bundle Mode — Phase 2. FBM is Vite's bundled dev mode, so the leak accumulates over long-lived Vite dev sessions that emit/re-emit assets. The roadmap classifies it as lower-priority memory safety rather than an adoption blocker, but it degrades long-running dev servers.
Related: rollup#6095 (counterpart request; reference for the API discussion) · tracked under #10019 §6.
What does the proposed API look like?
The concrete API/approach still needs investigation by whoever picks this up — this request is to schedule that work, not to lock in a design. The exact Rolldown API is open and need not match Rollup's: rollup#6095 is a reference for the discussion, not a spec to copy. Ideally the user shouldn't have to manage this by hand at all.
Most promising direction — automatic cleanup via needsCodeReference. Files emitted with needsCodeReference: true can be released by Rolldown without any plugin cooperation: if the latest output no longer references the emitted file, Rolldown is free to drop it. This covers the common new URL(..., import.meta.url) asset case and requires no new plugin API, so it's the cleanest starting point. (sapphi-red raised this in rollup#6095, and it lines up with "it would be nice if the user doesn't have to manage this manually.")
See rollup#6095 for the fuller discussion and other API options to draw from.
Source: rolldown/rolldown