winform PictureBox 显示目录下的图片太费内存

不知道有没有可以让内存少点的办法
2025-06-20 13:45:57
推荐回答(1个)
回答1:

给picturebox指定新图片前,要主动释放旧图片占用的内存

(vb代码)

If Not (Me.PictureBox1.Image Is Nothing) Then
    PictureBox1.Image.Dispose()
    PictureBox1.Image = Nothing
End If

C#

if ((this.PictureBox1.Image != null)) {
    PictureBox1.Image.Dispose();
    PictureBox1.Image = null;
}