关于内存的问题:很快把我512M内存耗尽
我写的一屏保程序,每3S从资源里读取变换一张图片。
下面是关于换图片的代码:
每换一第图片,内存就多用4M左右,我一时也想不出,为什么。有时到了内存会自动释放,有时,则
一直到耗尽内存为止。
private void changeFile()
{
Random r = new Random();
int fileLen = 1;
//把图片做成资源的形式
string[] fileToDisplay ={"DSCF0025.JPG",
"DSCF0029.JPG",
"DSCF0036.JPG",
"DSCF0004.JPG",
"DSCF0012.JPG",
"DSCF0015.JPG",
"DSCF0002.JPG",
"DSCF0010.JPG",
"DSCF0043.JPG",
"DSCF0048.JPG"
};
fileLen = fileToDisplay.Length ;
ResourceManager rm = new ResourceManager ("cCharp.My",Assembly.GetExecutingAssembly ());
Image MyImage = (Bitmap)rm.GetObject(fileToDisplay[r.Next (fileLen)]);
if (MyImage.Width > 800)
{
if (MyImage.Width > MyImage.Height )
{
picBox.Width = 640;
picBox.Height =480;
}
else
{
picBox.Width = 480;
picBox.Height =600;
}
picBox.SizeMode = PictureBoxSizeMode.StretchImage ;
}
else
{
picBox.SizeMode = PictureBoxSizeMode.AutoSize ;
}
picBox.Image = (Image)MyImage;
//
MovePic();
}