How to dispose of DOM elements in JavaScript to avoid memory leaks

前端 未结 4 939
滥情空心
滥情空心 2020-12-13 00:58

I have an application that allows a user to view details on a specific case w/out a postback. Each time a user requests data from the server I pull down the following marku

4条回答
  •  遥遥无期
    2020-12-13 01:34

    function discardElement(element) {
        var garbageBin = document.getElementById('IELeakGarbageBin');
        if (!garbageBin) {
            garbageBin = document.createElement('DIV');
            garbageBin.id = 'IELeakGarbageBin';
            garbageBin.style.display = 'none';
            document.body.appendChild(garbageBin);
        }
        // move the element to the garbage bin 
        garbageBin.appendChild(element);
        garbageBin.innerHTML = '';
    }
    

    Source

提交回复
热议问题