VB.Net程序内存释放类

 

#Region "内存释放"
'需要Imports System.Runtime.InteropServices
<DllImport("kernel32.dll")> _
Public Function SetProcessWorkingSetSize( _
ByVal hProcess As Integer, _
ByVal dwMinimumWorkingSetSize As Integer, _
ByVal dwMaximumWorkingSetSize As Integer) _
As Integer

End Function

<DllImport("kernel32.dll")> _
Public Function GetCurrentProcess() As Integer
End Function

Public Sub ReduceMem() '方法一
System.Diagnostics.Process.GetCurrentProcess.MinWorkingSet = New System.IntPtr(5)
System.Diagnostics.Process.GetCurrentProcess.MinWorkingSet
= New System.IntPtr(5)
'ReDuceMem()'需要释放内存的时候直接调用这个函数就OK
End Sub

Private Sub ReduceMemory() '方法二
SetProcessWorkingSetSize(GetCurrentProcess, -1, -1)

End Sub


#End Region

转载于:https://www.cnblogs.com/hsyz/archive/2011/08/31/2161071.html

你可能感兴趣的:(VB.Net程序内存释放类)