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

后端 未结 3 1370
别跟我提以往
别跟我提以往 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:23

    $('#myDiv').remove();
    

    or

    function removeElement(divNum) {
        var d = document.getElementById('myDiv');
        var olddiv = document.getElementById(divNum);
        d.removeChild(olddiv);
    }
    

    Would remove it from the DOM however it won't free up any memory, or bandwidth or http requests...so performance wise it won't make much of a difference (not taking rendering into account).

    However I believe if the image is removed from the DOM the memory it uses will eventually be managed and removed by the browser (garbage collection).

    So in short no I don't think there is a specific way to remove it from memory because that is a browser-level concern..

提交回复
热议问题