2
RemoveRangeを使用すると、アイテムがメモリ内に残っているように見えます。私がこれらの項目について知っている他の参照はありません。私はちょうど私が望むアイテムをコピーし、古いリストを完全に消去する回避策を使うべきですか?c#リスト<T> RemoveRange削除したアイテムはどうなりますか?
private void Form1_Load(object sender, EventArgs e)
{
bmp = new Bitmap(5000, 5000, PixelFormat.Format32bppPArgb);
pictureBox1.Image = bmp;
pictureBox1.Width = bmp.Width;pictureBox1.Height = bmp.Height;
bmp2 = new Bitmap(some_image_file);//500x500 bitmap
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
bitmap_list.Add(new Bitmap(bmp));
Graphics.FromImage(bmp).DrawImage(bmp2, e.X - bmp2.Width/2, e.Y - bmp2.Height/2);
pictureBox1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{// where do the items go? memory is not freed until running a manual GC
bitmap_list.RemoveRange(1, bitmap_list.Count - 1);
}
private void button2_Click(object sender, EventArgs e)
{// if this is not clicked, memory will run out even after clearing the list
// down to one item
GC.Collect();
}
感謝を:
は説明するために例を作りましたよ!
ありがとうございました。私は通常、多くを処分しますが、何らかの理由でここでそれを考えなかったのです。 – george