'Is an Image object without references marked for garbage collection as usual?
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;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
