Skip to content

[Web] FileKit.download never revokes object URLs on JS and Wasm #719

Closed

Description

@xchacha20-poly1305

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

  1. 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")
  1. Repeat the action several times without reloading the page.
  2. Observe calls to URL.createObjectURL and URL.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

  1. vinceglb commented on Nov 18, 2026

    @vinceglb
    Owner

    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.download was 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.

  2. added a commit that references this issue on Nov 19, 2026
    9e5c637
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions