我正在处理有许多表单打开和关闭操作的反馈应用程序。当我启动应用程序时,我注意到内存中的一些变化,它占用25 MB。每当用户给出反馈意见时,内存使用量就会增加3 MB。在每个表单上,当从一个表单跳转到另一个表单或进行任何关闭操作时,我都使用了this.close()。什么可能导致内存增加?
我需要手动调用垃圾收集器吗?但每个人都说这样做不好。
在此过程中,我使用了双监视器方案,每500毫秒后应用程序对辅助屏幕进行快照,并在主屏幕上显示。为此,我使用了如下代码:
为了在打开另一个表单时关闭当前表单,我使用下面的代码:
我需要手动调用垃圾收集器吗?但每个人都说这样做不好。
在此过程中,我使用了双监视器方案,每500毫秒后应用程序对辅助屏幕进行快照,并在主屏幕上显示。为此,我使用了如下代码:
public EntryForm()
{
sc = Screen.AllScreens;
dbDms = new HondaDb(UtilityFunctions.getServerConnection());
db = new HondaDb(UtilityFunctions.getClientConnection());
bmpScreenshot = new Bitmap(sc[1].Bounds.Width,
sc[1].Bounds.Height,
PixelFormat.Format32bppArgb);
Create a graphics object from the bitmap.
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
Timer timerClientScreen = new Timer();
timerClientScreen.Interval = 500;
timerClientScreen.Enabled = false;
timerClientScreen.Start();
timerClientScreen.Tick += new EventHandler(timer_TickClient);
}
void timer_TickClient(object sender, EventArgs e)
{
// Take the screenshot from the upper left corner to the right bottom corner.
gfxScreenshot.CopyFromScreen(sc[1].Bounds.X, sc[1].Bounds.Y,
0, 0, sc[1].Bounds.Size, CopyPixelOperation.SourceCopy);
// Save the screenshot to the specified path that the user has chosen.
pictureBoxClient.Image = bmpScreenshot;
}
为了在打开另一个表单时关闭当前表单,我使用下面的代码:
formOpen.show();
formClose.Close();
请给我建议,如何减少内存使用。