admin管理员组文章数量:1355532
Am I required to hold ref to HTMLImageElement
to prevent it from being gc'ed befor its load
/error
events will be fired?
for example:
/**
* @param { string[] } urls
* @returns { Promise<HTMLImageElement[]> }
*/
function loadImages(urls) {
return new Promise(function(resolve) {
/**@type { HTMLImageElement[] } */
const images = [];
let i = urls.length;
/**@this { HTMLImageElement } */
function onLoad() {
images.push(this);
if (--i === 0) resolve(images);
}
function onError() {
if (--i === 0) resolve(images);
}
for (const url of urls) {
const image = new Image();
image.src = url;
image.addEventListener("load", onLoad);
image.addEventListener("error", onError);
}
});
}
is it possible to some of images being lost due to gc or not ?
it looks like i really need to do it, but there also can be some special rule for cases like this
本文标签: javascriptJS HTMLImageElement and garbage collectionStack Overflow
版权声明:本文标题:javascript - JS HTMLImageElement and garbage collection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744034988a2579603.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论