How to release object URLs after an icon preview changes
Answer in brief
Track the object URL created for each local file preview and revoke it when the preview no longer needs it. Keep the active URL alive while the user can still interact with the image.
Exercise repeated replacements
Select three local icons in sequence. Create a new object URL for each, remove the previous preview and revoke its old URL. Clean up the remaining URL when the editor closes.
Keep shared previews alive until their last use
The same local icon may appear in both a crop dialog and a thumbnail strip. Closing the dialog should not release a URL the strip still needs. Decide who owns the URL, and let that owner revoke it after both views release the file or after the file is replaced everywhere.
Sources
- [1] URL: revokeObjectURL() static method - Web APIs — MDN Web Docs, accessed November 23, 2026
Frequently asked questions
Should I revoke immediately after assigning src?
Allow the preview and any supported interactions to finish using the URL. Revoke it when the resource is no longer needed.