Re: FindFirstFile Possible Memory Leak
- From: Bob O`Bob <filterbob@xxxxxxxxxxxxxxx>
- Date: Tue, 12 Jun 2007 19:48:59 -0700
Stefan Berglund wrote:
It strikes me that one should close every handle but I have an
example that does this:
Dim WFD As WIN32_FIND_DATA
Dim hFile As Long: hFile = FindFirstFile(sProgramFiles & "*.*", WFD)
If (hFile > 0) Then
Do
Dim lngEnd As Long: lngEnd = InStr(1, WFD.cFileName, Chr$(0))
Dim sName As String: sName = Trim$(Mid$(WFD.cFileName, 1, lngEnd - 1))
If (WFD.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY) Then
Dim sVersions As String: sVersions = sVersions & sName & "|"
End If
Loop Until FindNextFile(hFile, WFD) = 0
End If
Call FindClose(hFile)
Wouldn't it be more correct to close each handle inside the loop?
Is that not necessary or am I creating a memory leak?
A simple google on "FindNextFile" clears that up enough for my taste.
Since it requires a handle already initialized by FindFirstFile or
FindFirstFileEx, and also explicitly calls for closing the handle
afterward, I would say it implicitly promises to do things the right way.
Call it "handle recycling" if you like.
By the way, to limit how distracted people get here in the groups
by things irrelevant to your question, I *strongly* recommend you
rewrite the %$#^%$#^%ing colons out of your code before posting.
Bob
--
.
- Follow-Ups:
- Re: FindFirstFile Possible Memory Leak
- From: Robert Morley
- Re: FindFirstFile Possible Memory Leak
- From: youare
- Re: FindFirstFile Possible Memory Leak
- From: Ralph
- Re: FindFirstFile Possible Memory Leak
- References:
- FindFirstFile Possible Memory Leak
- From: Stefan Berglund
- FindFirstFile Possible Memory Leak
- Prev by Date: Re: FindFirstFile Possible Memory Leak
- Next by Date: Re: Compile Only
- Previous by thread: Re: FindFirstFile Possible Memory Leak
- Next by thread: Re: FindFirstFile Possible Memory Leak
- Index(es):
Relevant Pages
|
Loading