我在 VB.NET 中开发了桌面应用程序。框架为 3.5,后端为 SQL Server 2005。
下面是我以主表单编写的代码[在表单关闭时释放内存],所有表单都继承自该代码。
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean
Private Declare Function EmptyWorkingSet Lib "psapi.dll" (ByVal hProcess As IntPtr) As Long
Private Sub frmEMR_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
GC.Collect()
GC.WaitForPendingFinalizers()
GC.RemoveMemoryPressure(GC.GetTotalMemory(True))
EmptyWorkingSet(Process.GetCurrentProcess.Handle)
SetProcessWorkingSetSize(Process.GetCurrentProcess.Handle, -1, -1)
End Sub
虽然我写过这个堆内存有争议的增加。
非托管内存也在增加。
任何人都可以帮助我解决这个问题。
感谢和问候
赫马尔沙阿