Repository navigation
Description
FileKit version
0.17.1 (latest release). The same code is present on main at fb02b46.
Modules
- filekit-core
Affected platforms
- Wasm (browser): download flow exercised in Chromium; missing cleanup confirmed by source inspection.
- JS (browser): the same missing cleanup is present in the implementation; not separately runtime-tested.
Environment
- Linux, headless Chromium 157
- Compose Multiplatform 1.12.2
- FileKit 0.17.1
What happened?
FileKit.download(bytes, fileName) creates a File, calls URL.createObjectURL(file), assigns the URL to an anchor and clicks the anchor. Neither implementation revokes the object URL afterward:
Downloads themselves succeed. However, each call leaves another object URL alive for the lifetime of the document. This can retain the backing file data during repeated downloads in a long-lived web app.
MDN's blob URL memory-management documentation explains that an active object URL prevents its backing object from being garbage-collected, and that URLs are automatically released when the document is unloaded.
Expected: FileKit should own the lifecycle of the URL it creates and revoke it once it is safe to do so, without interrupting downloads. The caller does not receive the URL and therefore cannot clean it up through the public API.
Steps to reproduce
- In a JS or Wasm app, call this from a user-triggered coroutine:
import io.github.vinceglb.filekit.FileKit
import io.github.vinceglb.filekit.download
FileKit.download(ByteArray(1024 * 1024) { 42 }, "example.bin")- Repeat the action several times without reloading the page.
- Observe calls to
URL.createObjectURLandURL.revokeObjectURL, for example with DevTools instrumentation installed before clicking the download button:
window.filekitUrlProbe = (() => {
const originalCreate = URL.createObjectURL;
const originalRevoke = URL.revokeObjectURL;
const active = new Set();
URL.createObjectURL = function (...args) {
const url = originalCreate.apply(this, args);
active.add(url);
return url;
};
URL.revokeObjectURL = function (url) {
active.delete(url);
return originalRevoke.call(this, url);
};
return {
active,
restore() {
URL.createObjectURL = originalCreate;
URL.revokeObjectURL = originalRevoke;
},
};
})();The current implementation creates a new URL per download and has no corresponding revocation path. filekitUrlProbe.active.size can be used to inspect the outstanding URLs; call filekitUrlProbe.restore() afterward.
Verification scope
The Wasm download flow was exercised successfully twice in a real Compose web app. The missing cleanup is established by the implementations linked above. No heap profiling or quantitative retained-memory measurement was performed, and the instrumentation above is provided as a minimal diagnostic rather than a claimed recorded measurement.
Possible fix
Retain the generated URL locally and schedule URL.revokeObjectURL(url) at a browser-safe time after triggering the download, including cleanup if triggering the download fails. Apply the same lifecycle handling to both JS and Wasm. A regression check could verify that repeated successful downloads eventually revoke their generated URLs while preserving downloaded bytes.
Activity
vinceglb commentedon Nov 18, 2026
Thanks for the detailed report and the probe snippet, it made this easy to confirm. Both the JS and Wasm implementations had this since
FileKit.downloadwas added. #721 revokes the object URL 40 seconds after the click (the delay FileSaver.js uses, so slower browsers can still read the blob), or right away if starting the download fails.🐛 Revoke object URLs created by FileKit.download on web