了解客户端文件的对象 URL 以及如何释放内存
我正在使用 createObjectURL
获取本地图像文件的引用 URL。当我处理完文件/图像后,我调用 revokeObjectURL
来释放该内存。一切对我来说都很好,但我只是想确保我释放了我能释放的所有内存。
在检查 chrome://blob-internals
页面后,我开始担心。在调用 createObjectURL
并使用图像后,我注意到创建了两个条目。一张有网址的 blobinternal:///d17c4eef-28e7-42bd-bafa-78d5cb86e761
和另一个
blob:http://localhost/dbfe7b09-81b1-48a4-87cd-d579b96adaf8
不过,两者都引用相同的本地文件路径。调用 revokeObjectURL
后,仅从 chrome://blob-internals
中删除了第二个条目。为什么会发生这种情况,如何删除其他条目以及这两种类型之间有什么区别?
另外,我还看到过人们在使用图像之前就撤销 URL 的例子。这有什么作用呢?
对这个主题的一些见解将不胜感激! :)
编辑: 我在 jsfiddle 创建了一个示例。因此,首先打开 blobinternals 并删除任何现有的 blob。然后运行 jsfiddle 示例,并在您的计算机上选择一个图像文件。然后刷新 blobinternals 以查看它添加的内容。然后在我的示例中单击“撤销 URL”。最后刷新 blobinternals 以查看剩余的 blob。
I am using createObjectURL
to get a reference URL to a local image file. When I am done with the file/image, I call revokeObjectURL
to free that memory. Everything works fine for me but I just want to be sure that I am releasing all the memory I can.
My concern arose after I inspected the chrome://blob-internals
page. Upon calling createObjectURL
and using the image, I noticed two entries were created. One with urlblob:blobinternal:///d17c4eef-28e7-42bd-bafa-78d5cb86e761
and the other
blob:http://localhost/dbfe7b09-81b1-48a4-87cd-d579b96adaf8
Both referred to the same local file path though. Upon calling revokeObjectURL
only the second entry was removed from chrome://blob-internals
. Why does this occur, how do I get rid of the other entry and what is the difference between the two types?
Also, I have seen examples of people revoking the URL before even using the image. What effect does this have?
Some insight into the topic would be much appreciated! :)
EDIT:
I've created an example at jsfiddle. So first open blobinternals and remove any existing blobs. Then run the jsfiddle example, and choose an image file on your machine. Then refresh blobinternals to see what it added. Then click "revoke URL" in my example. Finally refresh blobinternals to see what blobs remain.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一个引用(以
blob:blobinternal
开头的引用)似乎由input type="file"
元素保存。我修改了你的函数来重置输入的值,当我单击撤销 URL 按钮时,所有引用都被清除:在 Chrome Canary 中测试。
The other reference (the one beginning with
blob:blobinternal
) seems to be held by theinput type="file"
element. I modified your function to reset the value of the input, and when I click the revoke URL button, all the references are cleared:Tested in Chrome Canary.