Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is there a 40-second delay in calling the URL.revokeObjectURL method? #811

Open
mrdulin opened this issue Jul 12, 2024 · 3 comments
Open

Comments

@mrdulin
Copy link

mrdulin commented Jul 12, 2024

I asked same question on Stack Overflow, see here.

The source code FileSaver.js#L106

a.href = URL.createObjectURL(blob)
setTimeout(function () { URL.revokeObjectURL(a.href) }, 4E4) // 40s
setTimeout(function () { click(a) }, 0)

Why is there a 40-second delay in calling the URL.revokeObjectURL method? Why don't call it immediately after calling URL.createObjectURL(blob)?

@dongyuwei
Copy link

https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static

The revokeObjectURL() static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL().

Call this method when you've finished using an object URL to let the browser know not to keep the reference to the file any longer.

So the 40-second delay is just to relase the resource, prevent any memory leak.

@mrdulin
Copy link
Author

mrdulin commented Jul 17, 2024

https://developer.mozilla.org/en-US/docs/Web/API/URL/revokeObjectURL_static

The revokeObjectURL() static method of the URL interface releases an existing object URL which was previously created by calling URL.createObjectURL().

Call this method when you've finished using an object URL to let the browser know not to keep the reference to the file any longer.

So the 40-second delay is just to relase the resource, prevent any memory leak.

Why 40 seconds rather than 30 seconds or 60 seconds?

@dongyuwei
Copy link

Maybe 40 seconds or 30 seconds or 60 seconds are all okay, seems to don't matter.
I guess it's just used to wait and ensure the file is downloaded completely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants