- GC.Collect();
- //下面這行是重點
- GC.WaitForPendingFinalizers();
-
- 或採用 Windows API [C#][VB.NET]壓縮.NET程式的記憶體用量
- 這招好像不錯喔,有空來試試看!
-
-
- 底下有更好的範例:引用來源:your VB .NET App taking up too much memory??
-
- Public Class MemoryManagement
-
- Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" ( _
- ByVal process As IntPtr, _
- ByVal minimumWorkingSetSize As Integer, _
- ByVal maximumWorkingSetSize As Integer) As Integer
-
- Public Shared Sub FlushMemory()
- GC.Collect()
- GC.WaitForPendingFinalizers()
- If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
- SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
- End If
- End Sub
-
- End Class
沒有留言:
張貼留言