is Javascript able to unload an image from an HTML page?

后端 未结 3 1414
别跟我提以往
别跟我提以往 2021-01-18 06:32

I would like to know if it is possible to unload an image from an HTML page and free its memory occupation with some Javascript instructions. Say an image is already display

3条回答
  •  温柔的废话
    2021-01-18 07:09

    You can free memory of an img element by assigning the src attribute to a 1x1 pixel before removing it.

    const imgElement = document.querySelector(selector);
    imgElement.setAttribute('src', '/images/pixel.gif');
    imgElement.parentElement.removeChild(imgElement);
    

提交回复
热议问题