Advertisement
Guest User

Otimizar Ram VB.NET

a guest
Jul 21st, 2016
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean
  2. Public Class FreeMemory
  3. Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" ( _
  4. ByVal process As IntPtr, _
  5. ByVal minimumWorkingSetSize As Integer, _
  6. ByVal maximumWorkingSetSize As Integer) As Integer
  7. Public Shared Sub FlushMemory()
  8. Try
  9. GC.Collect()
  10. GC.WaitForPendingFinalizers()
  11. If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
  12. SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
  13. End If
  14. Catch ex As Exception
  15. End Try
  16. End Sub
  17. End Class
  18. Public Sub SetProcessWorkingSetSizeEx()
  19. Dim mProc As Process
  20. mProc = Process.GetCurrentProcess()
  21.  
  22. ' Imported function call
  23. SetProcessWorkingSetSize(mProc.Handle, -1, -1)
  24.  
  25. End Sub
  26. Public Sub New()
  27. MyBase.New()
  28.  
  29. 'This call is required by the Windows Form Designer.
  30. InitializeComponent()
  31.  
  32. 'Add any initialization after the InitializeComponent() call
  33.  
  34. End Sub
  35. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  36. If disposing Then
  37. If Not (components Is Nothing) Then
  38. components.Dispose()
  39. End If
  40. End If
  41. MyBase.Dispose(disposing)
  42. End Sub
  43.  
  44. Private Sub CLEAR_Tick(sender As Object, e As EventArgs) Handles CLEAR.Tick
  45. SetProcessWorkingSetSizeEx()
  46. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement