Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

URLDownloadToFile API Leaking Memory

Status
Not open for further replies.

Fencliff

Programmer
Apr 16, 2008
2
DK
Hi,

I have a problem with the URLDownloadToFile API reserving a large chunk of memory, and I can't figure out how to free it. My program is an app that runs in the background, downloading multiple Excel workbooks (.xls) from a web page.

When the first file is downloaded, the memory usage of the process jumps from ~5Mb to ~70Mb and stays there. The memory consumption doesn't increase with subsequent calls to the API.

Here is the relevant code:
Code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
        "URLDownloadToFileA" ( _
        ByVal pCaller As Long, _
        ByVal szURL As String, _
        ByVal szFileName As String, _
        ByVal dwReserved As Long, _
        ByVal lpfnCB As Long) As Long


Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000

Public Function bHTTPDownloadFile(sSourceUrl As String, _
                sLocalFile As String) As Boolean
  
  'Download the file. BINDF_GETNEWESTVERSION forces the API to download from the specified source.
  'Passing 0& as dwReserved causes the locally-cached copy to be downloaded, if available. If the API
  'returns ERROR_SUCCESS (0), DownloadFile returns True.
   bHTTPDownloadFile = URLDownloadToFile(0&, _
                                    sSourceUrl, _
                                    sLocalFile, _
                                    BINDF_GETNEWESTVERSION, _
                                    0&) = ERROR_SUCCESS
                                    
End Function

Worthy of noticing, that the exact same behavior is elicited when calling the API with null arguments, as instructed on some websites:

Code:
URLDownloadToFile(0, sSourceUrl, sLocalFile, 0, 0)

Does anybody have any idea why this is happening? Any tidbit of information would be valuable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top