Do I always need to call URL.revokeObjectURL() explicitly?
blob, garbage-collection, javascript, memory-leaks
Solution
Is it safe to depend on browser's garbage collector to avoid any memory leak?
What `createObjectURL` approximately¹ does is to create a mapping of the ID in the created blob URL to the actual blob in a hidden `Map` associated with the current global object. Which means from the perspective of the GC the Blob remains reachable until either the global itself becomes collectible - commonly when you navigate away from the page or close a tab - or when the mapping is revoked (assuming that was the last reference).
So it depends on what you consider as a leak. It won't remain alive for the lifetime of the browser, only for the lifetime of the current page. You need to revoke if you want its lifetime to be potentially shorter than the current page.
¹ That's not exactly how it's implemented, but it describes the behavior reasonably well when reasoning about reachability.
Problem
I'm using blob to download files, Problem is I want to keep Object URL even after downloading the file, without making major changes in code base. So one of the option is not to call `URL.revokeObjectURL();` Is it safe to depend on browser's garbage collector to avoid any memory leak? Do I always need to call `URL.revokeObjectURL();` explicitly ?