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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory usage grows inexplicably

Status
Not open for further replies.

joeschoe

Programmer
Jan 13, 2002
67
IL
My applcation waits for email to arrive. While waiting, I have a timer routine that checks the incoming folder.
Even when no email arrives the program slowly "grows" in memory.
When I run a utility like MAxMem, the memory usage shrinks.
Is there a way to invoke this shrinking from within the application?
The growth is very minimal, 4K per minute,but this program is supposed to run unattended for months at a time.
 
Hi joeschoe

sounds like you're not releasing objects at the end of your procedure.

remember to use set {object} = nothing for anything created.

posting a bit of code will help to see what you're creating



SteveO
 
Thanks SteveO for replying. I do set all objects to nothing. The only repetitive code that gets executed when there are no emails coming in, is the following.
Code:
Private Sub XtractDir(srcDir As String, LinAr As String)
'extract 10 filenames at a time 
' reads directory contents of sRCdir and stores the filename and length in a string '
' the filename is delimited with []followed by the length                           '
' all is trimmed so there should be no gaps                                         '
'Some incoming mails are slow to arrive and the test for  FileLocked is to avoid processing unfinished emails
   Dim i As Integer
   Dim FN As String
   Dim FL As Long
   Dim p As Long
   On Error GoTo ErrTrapX
   FN = Dir(srcDir)
   FN = Trim(FN)
   If Len(FN) = 0 Then
      Exit Sub     'exit point if the folder is empty
   End If
   i = 0
   LinAr = ""
Do While Len(FN) > 0 And i < 10
      DoEvents
      On Error Resume Next
      FL = FileLen(srcDir + FN)
      If Err.Number > 0 Then
        GoTo Cont1
      End If
      If FileLocked(srcDir & FN) Then
        GoTo Cont1
      End If
        If FL > 0 Then
           i = i + 1
           LinAr = LinAr + "[" + FN + "]" + Trim(Str(FileLen(srcDir + FN)))
        End If
Cont1:
      On Error Resume Next
      FN = Dir()
      If Err.Number > 0 Then
        LogIt "XtractDir " & Err.Description
        Exit Sub
      End If
      FN = Trim(FN)
   Loop
   Exit Sub
ErrTrapX:
   LogIt ("xtractdir (" + srcDir + ") " + Err.Description)
   Err.Clear
End Sub
 
Code:
LinAr = LinAr + "[" + FN + "]" + Trim(Str(FileLen(srcDir + FN)))

maybe the problem....

How / where is LinAr dim'ed? You may have better luck if you declare it explicitly inside the function.

Are you using OPTION EXPLICIT?


Take Care

Matt
If at first you don't succeed, skydiving is not for you.
 
Matt,Thanks for replying.

The LinAr is defined as a string in the timer's subroutine.
I do use Option Explicit.

I must mention I have been honing my code to overcome this problem for 6 weeks.
I really think its a windows feature, that does not clear out variables until the system needs more memory. Is this a possibility?
 
As a point of interest, wouldn't it be great if you didn't have to poll for the arrival of email (or, rather, the creation of a file in a particular folder)? Wouldn't it be great if the OS told you instead?

Thread222-576673
thread222-719707
 
strongm, you are right.
I have an smtp server module doing just that, but I use it to write to the folder.
My major programming effort happens after the arrival when I do all wierd and wonderful things to the email such as encryption, tracking and virus checking.
I initially wrote the smtp server myself using winsock, but later, when I needed multi-inputs in parallel, I purchased a module from WeOnlyDo Software.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top