在JavaScript中創建新的圖像元素時,Google Chrome的內存工具(開發人員工具>時間軸>內存)自然會將其視爲新的DOM元素。配置圖像對象
在我的情況下,我結束了1500多個DOM元素,我希望擺脫它們。我試圖保存所有對象的數組,並刪除所有的人都在一個循環中時,我已經準備好創建的所有對象,導致以下錯誤:
Uncaught TypeError: Cannot call method 'removeChild' of null
表示圖像的對象不出現在實際的DOM中。
var images = [];
var i, image;
for(i = 0; i < urls.length; i++) {
image = new Image();
image.src = urls[i];
}
// other stuff happens
for(i = 0; i < images.length; i++) {
// apparently this doesn't work because I'm not adding the image to my DOM
// images[i].parentNode.removeChild(images[i]);
// delete images
}
有沒有辦法刪除/刪除/復位/配置Image對象?
謝謝!我知道你的答案是最後一次,但你實際上已經做了一些研究 –
這已得到修復,因爲或這仍然是一個錯誤嗎? – Hackeron