Please help with this memory leak

Results 1 to 2 of 2

Thread: Please help with this memory leak

  1. #1
    Join Date
    Dec 1969

    Default Please help with this memory leak

    Below you will find the code for a windows service that I created. Everything is working as it should, but my memory on this just keeps climbing. <BR><BR>What this serviced does is every time a new pdf document is added to a folder, a check is performed. <BR><BR>The check is to loop through each file in the folder, check the file to see if is more than 60 min old and if so delete it. <BR><BR>The more times we add files and files get removed, the higher the memory goes. <BR><BR>Here is the code, and thank you for your time. <BR><BR><BR> Public folderToWatch As FileSystemWatcher <BR> Public myDirectory As System.IO.Directory <BR> Public myFilePath As String <BR> Public item As String <BR><BR> Protected Overrides Sub OnStart(ByVal args() As String) <BR> myFilePath = "C:fileTest" <BR> folderToWatch = New FileSystemWatcher <BR><BR> With folderToWatch <BR> .Path = myFilePath <BR> .Filter = "*.pdf" <BR> .NotifyFilter = .NotifyFilter <BR> End With <BR><BR> AddHandler folderToWatch.Created, AddressOf deleteFiles <BR> folderToWatch.EnableRaisingEvents = True <BR> End Sub <BR><BR><BR> Private Sub deleteFiles(ByVal source As Object, ByVal evt As FileSystemEventArgs) <BR> &#039; Loop through all the files in the directory <BR> myDirectory.SetCurrentDirectory(myFilePath) <BR><BR> For Each item In myDirectory.GetFiles(myFilePath) <BR> &#039; If the file was created 60 min ago or longer <BR> If File.GetCreationTime(item).AddMinutes(60) &#060; Now() Then <BR> &#039; set the file to normal, it may be read only <BR> File.SetAttributes(item, FileAttributes.Normal) <BR> &#039; delete the file <BR> File.Delete(item) <BR> End If <BR> Next <BR> End Sub <BR><BR> Protected Overrides Sub OnStop() <BR> &#039; Add code here to perform any tear-down necessary to stop your service. <BR> End Sub

  2. #2
    Join Date
    Dec 1969

    Default * Repost.

    Only 1 thread is necessary. If we can help, we will.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts