[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Memory Usage Increases constantly for Directory.GetFiles

Karthikeyan C S

10/8/2003 4:21:00 PM


I wrote an windows application in VB.NET which browses a
specific folder for files, say c:\temp, repeadlty in a
timer.

Each time the timer is executed (which has only one line
of code, code shown below) the [Memory usage] in
the "Windows Task Manager" for this application
continously increases by 8K.

When the timer is stoped the Memory stabilizes.

How can this Memory usage can be controlled or is this due
to the problem with the Garbage Collector of the CLR.

--------

'code for the timer1 Tick event ::

Private Sub Timer1_Elapsed(ByVal sender As System.Object,
ByVal e As System.Timers.ElapsedEventArgs) Handles
Timer1.Elapsed

Dim files() As String = Directory.GetFiles("c:\temp\")

End Sub
---------

Regards

Karthikeyan C S
1 Answer

Michael Giagnocavo

10/8/2003 8:04:00 PM

0

What's most likely happening is that the memory is used, however, not enough
to trigger a collection. Most Win32 apps will use memory until there is a
reason to free up extra resources. If you open 50 instances of your app,
you'll see what I mean. But, as long as you have extra memory to spare, it
doesn't bother "cleaning up". This is not directly related to garbage
collection either. A GC will happen when the managed heap uses a certain
amount of memory.

You can play around with System.GC.Collect() and Win32's
Kernel32.dll!SetProcessWorkingSetSize if you want to see how it works.
Also, minimize applications (try yours, try Outlook, etc.) and see what
happens.

The real recommendation is that unless this is causing a specific problem
for you (a real problem, not just "I don't want it to look like it's going
to eat all my memory ;)"), then leave it alone.

-mike
MVP


"Karthikeyan C S" <c_s_karthikeyan@yahoo.com> wrote in message
news:002401c38db8$332a60a0$a401280a@phx.gbl...
>
> I wrote an windows application in VB.NET which browses a
> specific folder for files, say c:\temp, repeadlty in a
> timer.
>
> Each time the timer is executed (which has only one line
> of code, code shown below) the [Memory usage] in
> the "Windows Task Manager" for this application
> continously increases by 8K.
>
> When the timer is stoped the Memory stabilizes.
>
> How can this Memory usage can be controlled or is this due
> to the problem with the Garbage Collector of the CLR.
>
> --------
>
> 'code for the timer1 Tick event ::
>
> Private Sub Timer1_Elapsed(ByVal sender As System.Object,
> ByVal e As System.Timers.ElapsedEventArgs) Handles
> Timer1.Elapsed
>
> Dim files() As String = Directory.GetFiles("c:\temp\")
>
> End Sub
> ---------
>
> Regards
>
> Karthikeyan C S