Hello
as long as the application domain is loaded the memory will be reserved
for further processing
if your comp would run low on resources and the app does not need the memory
at the moment ( cause it is idle ,,, the memory would be given back and
needs to be reclaimed )
with a windows form application you can see this behavior to ( or did you
really thought a clean form needs about +- 25 megs in .Net ? )
there is a way you can bypass this behavior however it comes with a small
price ,,,,
i wrote once a remoting project , and had my customer complaining about the
memory consumption , so i digged a litle bit deeper and came with this
solution
my project ( wich is a singleton ) starts a timer that periodicly checks a
datetime var to see how manny time has passed after it was last called
if this intervall is >= 1 minute it will call SetProcessWorkingSetSize()
wich will trim the data usage to a minimum see below code ( sorry VB.Net
-) )
Private M_dtLastUsage As DateTime
Private oCallback As New TimerCallback(AddressOf OnTick)
Private oTimer As Threading.Timer
Public Sub OnTick(ByVal stateInfo As Object)
Dim DtCurrent As DateTime = Date.Now
Dim elapsed_time As TimeSpan
elapsed_time = DtCurrent.Subtract(M_dtLastUsage)
If elapsed_time.TotalMinutes >= 1 Then
oTimer.Dispose() : oTimer = Nothing
SetProcessWorkingSetSize()
End If
End Sub
Public Sub New()
M_dtLastUsage = Date.Now
If IsNothing(oTimer) Then
oTimer = New System.Threading.Timer(oCallback, Nothing,
System.TimeSpan.FromMinutes(0), System.TimeSpan.FromMinutes(1))
End If
End Sub
Private Declare Auto Function SetProcessWorkingSetSize Lib "kernel32.dll"
(ByVal procHandle As IntPtr, ByVal min As Int32, ByVal max As Int32) As
Boolean
Friend Sub SetProcessWorkingSetSize()
Try
Dim Mem As Process = Process.GetCurrentProcess()
SetProcessWorkingSetSize(Mem.Handle, -1, -1)
Catch ex As Exception
End Try
End Sub
The drawback of this method is that the framework needs to reclaim the
memory again so in theory your prog should be a few miliseconds slower as it
could be.
So it is more cosmetical as that it does really have a purpose as the prog
is actually gone to the swap same as a minimized application ( physical and
virtual memory thingy )
Regards
Michel Posseth [MCP]
"Stephany Young" wrote:
What you are talking about is the 'WorkingSet'. If you continue to refer to
is as 'working memory' then you all you are going to do is confuse everyone
including youself.
Have a look at the documentation on the System.Environment.WorkingSet64
property for some more information.
By 'when started minimized', I assume that you are refering to setting the
WindowState property of your startup form at design time.
Instaed of setting it at design time you could try setting it in your
Form.Load event handler.
"Allen" <Al***@discussions.microsoft.comwrote in message
news:4E**********************************@microsof t.com...
When minimizing Visual Basic application, working memory is greatly
reduced
from about 20 MB to only about 2 MB. However I want the application to
start as minimized, and most of the time it will remain minimized, never
being brought to normal or maximized view and consequently then minimized.
However when started minimized the working memory stays at 20 MB until the
app is restored to normal/maximized and then minimized.
How do I get the working memory down to 2 MB programmatically when
starting
the app minimized?
TIA