Monday, February 27, 2006

How to Avoid Memory Leaking in VB.NET

IN CODE after all code

GC.Collect()
If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
End If

FUNCTIONS that needs to be declared


#Region "Stuff for Closing the Processes"
'# to close all the resources
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As Boolean

Public Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process
Mem = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
#End Region

1 comment:

Anonymous said...

Can anyone recommend the robust Network Management program for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: [url=http://www.n-able.com] N-able N-central helpdesk software
[/url] ? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!