You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Amazingly, all the major browsers seem to suffer from a bug where repeatedly changing the src of an image, even just toggling it between 2 values, causes memory use to grow without bounds:
This bug renders image-defer's maxLoaded feature useless, and in fact image-defer just makes it worse when maxLoaded is in force, because it causes the src attributes to change more often than it otherwise would.
The issue is reproducible with the image-defer live demo page in latest Firefox 53 and Chrome 58. Just set the limit to 10 then repeatedly scroll up and down.
Given that the browser vendors haven't fixed this in 5 years, some kind of workaround will be needed. It might be possible, instead of just changing the src, to replace the image's DOM element with a clone of itself already set to the new src. The browser should then garbage collect the old DOM element along with the image data it contained. The DOM element in image-defer's _state.images will also need to be replaced.
The text was updated successfully, but these errors were encountered:
Changing the src by replacing the img with a clone looks to require something like this:
var clone = img.cloneNode(true);
clone.src = newsrc;
clone.addEventListener('load', clone._defer_load_event); // if _defer_load_event exists
img.parentNode.replaceChild(clone, img);
// then replace img with clone in _state.images
// img should be garbage collected if there are no other references to it
Amazingly, all the major browsers seem to suffer from a bug where repeatedly changing the
src
of an image, even just toggling it between 2 values, causes memory use to grow without bounds:This bug renders image-defer's
maxLoaded
feature useless, and in fact image-defer just makes it worse whenmaxLoaded
is in force, because it causes thesrc
attributes to change more often than it otherwise would.The issue is reproducible with the image-defer live demo page in latest Firefox 53 and Chrome 58. Just set the limit to 10 then repeatedly scroll up and down.
Given that the browser vendors haven't fixed this in 5 years, some kind of workaround will be needed. It might be possible, instead of just changing the
src
, to replace the image's DOM element with a clone of itself already set to the newsrc
. The browser should then garbage collect the old DOM element along with the image data it contained. The DOM element in image-defer's_state.images
will also need to be replaced.The text was updated successfully, but these errors were encountered: