2012年8月30日 星期四

釋放記憶體


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

沒有留言:

張貼留言