Skip to content

Browser bug: repeatedly changing image src causes a memory leak #2

Open
@fozcode

Description

@fozcode

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions