quarta-feira, novembro 09, 2005

PRB: Memory allocated in an Windows Application/Windows Service

Some times is possible to lose some performance and the Windows Application/Windows Service can't release the Objects Memory and the Server will go down.

To avoid this:

Include Code:
Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal dwMinimumWorkingSetSize As Int32, ByVal dwMaximumWorkingSetSize As Int32) As Int32

Public Function NewSaveMemory() As Int32
GC.Collect()
GC.WaitForPendingFinalizers()
SetProcessWorkingSetSize(-1, -1)
End Function

Include Timer (5sec):

Private Sub TimerCleanMem_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles TimerCleanMem.Elapsed
NewSaveMemory()
End Sub


This functions will release the memory that are in the Garbage Collector

I hope this help

Sem comentários: