JavaScript で新しい Image 要素を作成すると、Google Chrome のメモリ ツール (開発者ツール > タイムライン > メモリ) は、当然、それを新しい DOM 要素と見なします。
私の場合、最終的に 1500 以上の DOM 要素があり、それらを削除したいと考えています。すべてのオブジェクトを配列に保存し、すべてのオブジェクトを作成する準備が整ったときにループ内のすべてのオブジェクトを削除しようとしましたが、次のエラーが発生しました。
Uncaught TypeError: Cannot call method 'removeChild' of null
これは、Image オブジェクトが実際の 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 オブジェクトを削除/削除/設定解除/破棄する方法はありますか?