Reputation: 179
The problem is basically what the title says. The minimal example to demonstrate it is below.
This function accepts a File
object as an argument from <input type='file' />
field. It creates a URL and revokes it 5 seconds later.
const compress = (file) => {
const img = new Image();
img.src = URL.createObjectURL(file);
console.log('url created');
setTimeout(() => {
URL.revokeObjectURL(img.src);
console.log("url revoked");
}, 5000);
};
The blob appears in the Sources panel and I would expect it to disappear (to be garbage collected) after 5 seconds, but it doesn't.
What could be the reason it's not garbage collected?
It's also not removed from chrome://blob-internals/
As far as I understand it's a memory leak. How can I fix it?
Upvotes: 6
Views: 624