I have a method that updates an object with a new image each loop through an animation, but causes a continuing memory leak which eventually drops the rest of the animation to a standstill. This is roughly what the method is:
loadInstance(c) {
let promise = new Promise((resolve, reject) => {
//this is required because the new image is based on another image
//"this.icon" which is loaded before the animation loop.
if (this.icon !== false) {
//create a new image:
let img = new Image();
img.src = "testImg.png";
//load the image
img.onload = () => {
//initial image is set as false, check that this is not so
if (this.image !== false) {
//sets the image's onload and src to null
this.image.src = "";
this.image.onload = null;
}
//sets the new image to the object
this.image = img;
resolve();
};
}
}); //end promise
return promise;
}
Naturally I thought the leak was due to the new images still being referenced in memory and so I made sure to null each prior image before updating the next. This did help significantly, but I still seem to have a constant leak from something else linked to this method. I also nulled the onload method of the previous image, but still no change. Any ideas?