revokeObjectURL 回收worker中创建的数据

原文链接: revokeObjectURL 回收worker中创建的数据

上一篇: 图片 转 ico

下一篇: 用dom-to-image 将dom结点转图片

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

在worker中创建的就要在worker中调用, 在主页面创建的, 就要在主页面调用

revoke之后, 就不能再通过url来展示或者下载了, 会直接报错, 一定要在确定该url不用的情况下去释放资源, 同时在主页面也删除url

up-46b09879f71d5039ad124ee84d0a43f90a5.png

mdn上的解释是可以在worker中使用, 但是不能在sw中使用, 主要是再终止worker时, 将该worker创建的url所依赖的数据干掉, 给浏览器回收

The URL.revokeObjectURL() static method 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.

Note: This feature is available in Web Workers .

Note: This method is not available from service workers, due to issues with the Blob interface's life cycle and the potential for leaks

初始情况下没有imageData

up-e2984e64abe531b146c9e978b343cc88e85.png

我们创建一个并发送到worker后

up-f84b47c80a7872bf1e8cb2e4fa890eb9982.png

我们在worker中调用revokeObjectURL, 注意在哪里创建的就要在哪里调用, worker中创建的不能在主页面调用函数来销毁

up-92b521614b5259c9beb4ab6aac71da01c98.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值