.net程序瘦身(减少内存占用)
从网上搜到这段代码,剧说比较有效,贴上来,以后可能会有用:
声明如下函数
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean
创建一个过程
Public Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process
Mem = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
调用这个过程后你就会发现,你的程序占用的内存变小了
声明如下函数
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean
创建一个过程
Public Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process
Mem = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
调用这个过程后你就会发现,你的程序占用的内存变小了