没有引用的 Image 对象是否像往常一样标记为垃圾回收?
Audio()
声明如果当前正在播放,则垃圾收集机制不会将其对象从内存中删除。
当然,对于 Image() 来说,情况并非如此
对象,因为没有播放。
但由于两者都代表标签,我想知道Image对象的垃圾收集是否有特定的条件?
在画布元素上绘制图像可能是一个现实世界的示例:
function someFunc(url) {
let canvas1 = document.getElementById("canvas1");
let ctx1 = canvas1.getContext('2d');
// Is this image preserved after the callback was invoked?
let img = new Image();
img.addEventListener('load', function() {
ctx1.drawImage(img, 0, 0);
}, {once: true});
img.src = url;
}
The documentation for Audio()
states that its objects won't be removed from memory by the garbage collection mechanism if the playback is currently underway.
Of course the same cannot be true for Image()
objects as there is no playback.
But since both represent tags, I was wondering if there are specific conditions to the garbage collection of Image objects?
Drawing an image on a canvas element might be a real world example for this:
function someFunc(url) {
let canvas1 = document.getElementById("canvas1");
let ctx1 = canvas1.getContext('2d');
// Is this image preserved after the callback was invoked?
let img = new Image();
img.addEventListener('load', function() {
ctx1.drawImage(img, 0, 0);
}, {once: true});
img.src = url;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论