DIR function Memory Leak

  • Thread starter Thread starter VBProgrammer
  • Start date Start date
V

VBProgrammer

I think I have found a memory leak using the DIR function and also
using the System.IO.File.Exists. Create a new windows application,
place a timer on the form, in the Timar1_Tick event put:

If Dir("C:\SomeFile.txt") = "" then
End If

The "C:\SomeFile.txt" doesn't need to exist. you can also see the same
thing using:
If System.IO.File.Exists("C:\SomeFile.txt") Then
End If

Watch the memory of the process in task manager, and it grows.
Anybody have any thoughts?
 
If you force the garbage collector to do it's thing (GC.Collect()), either
every time (excessive) or every X times, does it still grow?

Jevon
 
VBProgrammer said:
I think I have found a memory leak using the DIR function and also
using the System.IO.File.Exists. Create a new windows
application, place a timer on the form, in the Timar1_Tick event
put:

If Dir("C:\SomeFile.txt") = "" then
End If

The "C:\SomeFile.txt" doesn't need to exist. you can also see the
same thing using:
If System.IO.File.Exists("C:\SomeFile.txt") Then
End If

Watch the memory of the process in task manager, and it grows.
Anybody have any thoughts?


Welcome to the world of garbage collection! ;-) Dir internally creates
object(s) and releases them but the GC won't collect them and free memory
before it thinks it's the time to do it.
Add
gc.collect
after the dir function call and watch the memory usage now - but just for
testing purposes.
 
Back
Top