Flush Virtual Memory?

munkee

Active member
Joined
Feb 20, 2007
Messages
43
Programming Experience
Beginner
Alright,
So I've been having issues with my application lately; as some of you might have read in my previous post.

I've gotten my application to flush memory using GC.Collect() - awesome! Now, how would I go about doing the same with my Virtual Memory? Is this even possible?

Maybe I'll soon get a good nights rest!


:confused:
 
This may do the trick for you...


VB.NET:
Public Class MemoryFlusher
  
  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

Note though... according to documentation this may cause unexpected behaviour...
 
Back
Top