felanor Posted December 21, 2008 Share Posted December 21, 2008 Hello Everyone, I am hoping to get some assistance finding the memory leak in my code. I've searched through it, but, alas, no luck finding it. I'm hoping that another few sets of eyes will help me find the error of my ways. When I run the program it starts off at about 9MB of memory used. As I leave it running it slowly builds. After running it for about 8 hours, it has jumped to 42MB of memory used. I had the program running for a few days and it was up to near 500MB, so I closed it down and restarted it. Here's the code, with company information taken out, of course. expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=D:\HFWErrorParser.exe #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** Opt("TrayIconDebug",1) ; Includes Section #include <array.au3> #include <INet.au3> #include <File.au3> Dim $aFiles[1] Dim $oMyRet $hString = "" ; Production Directories $prndirectory = "\\SERVERNAMEHERE\c$\Upnotes\GENERIC\Auto_prn" $archivedirectory = "\\SERVERNAMEHERE\c$\Upnotes\GENERIC\reviewed\logs" ; Test Directories ; $prndirectory = "D:\PNR" ; $archivedirectory = "C:\ARCHIVE" _SendAlert("Error Log Monitoring Started", "The error log monitoring program has started on " & @ComputerName, "", "my@email.com", "", "") While 1 $hSearch = FileFindFirstFile($prndirectory & "\*.prn") ReDim $aFiles[1] $aFiles[0] = 0 While 1 $file = FileFindNextFile($hSearch) If @error then ExitLoop _ArrayAdd($aFiles,$file) $aFiles[0] += 1 WEnd For $z = 1 to $aFiles[0]-1 $datestamp = StringLeft($aFiles[$z],8) $aErrorFile = StringSplit(StringReplace(FileRead($prndirectory & "\" & $aFiles[$z]),@CRLF,"|"),"|") If Not FileExists($prndirectory & "\"& $datestamp & "HFWErrors.txt") Then $sString = $aErrorFile[6] & @CRLF & $aErrorFile[7] & @CRLF & $aErrorFile[8] & @CRLF Else $sString = "" EndIf For $x = 1 to $aErrorFile[0] If StringInStr($aErrorFile[$x],"*") Then $sString &= $aErrorFile[$x-2] & @CRLF & $aErrorFile[$x-1] & @CRLF & $aErrorFile[$x] If $x + 1 <= $aErrorFile[0] Then If StringInStr($aErrorFile[$x+1],".") Then $sString &= StringTrimLeft($aErrorFile[$x+1],18) EndIf $sString &= @CRLF & @CRLF EndIf Next FileWrite($prndirectory & "\"& $datestamp & "HFWErrors.txt",$sString) FileMove($prndirectory & "\" & $aFiles[$z],$archivedirectory & "\" & $aFiles[$z],9) $sString = "" Next Sleep(5000) _EmailLog() WEnd Func _EmailLog() $hSearch = FileFindFirstFile($prndirectory & "\*HFWErrors.txt") Dim $aFiles[1] $aFiles[0] = 0 While 1 $file = FileFindNextFile($hSearch) If @error then ExitLoop _ArrayAdd($aFiles,$file) $aFiles[0] += 1 WEnd $z = 1 While $z < $aFiles[0] _SendAlert("Henry Ford Errors", "Greetings. Attached is the daily generated log file of export errors.", $prndirectory & "\" & $aFiles[$z]) FileMove($prndirectory & "\" & $aFiles[$z], $prndirectory & "\sent\" & $aFiles[$z], 9) $z += 1 WEnd EndFunc Func _SendAlert($SUBJECT, $BODY, $ATTACH = "", $TO = "TO@email.com", $CC = "CC@email.com", $BCC = "BCC@email.com") _INetSmtpMailCom("smtpout.secureserver.net", "Support", "support@domain.com", $TO, $SUBJECT, $BODY, $ATTACH, $CC, $BCC, "login", "password", "80") EndFunc Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "Error", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($s_Body, "<") And StringInStr($s_Body, ">") Then $objEmail.HTMLBody = $s_Body Else $objEmail.Textbody = $s_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) If FileExists($S_Files2Attach[$x]) Then $objEmail.AddAttachment($S_Files2Attach[$x]) Else $i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x] SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf If $ssl Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf $objEmail.Configuration.Fields.Update $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf EndFunc ;==>_INetSmtpMailCom Func OnAutoItExit() Switch @exitCode Case 0 $exit = "Natural Closing" Case 1 $exit = "Closed by Exit function" Case 2 $exit = "System Tray Exit" Case 3 $exit = "User Logoff" Case 4 $exit = "System Shutdown" EndSwitch _SendAlert("Error Log Monitoring Stopped", "The error log monitoring program has stopped on " & @ComputerName & "." & @CRLF & "Exit Code: " & @exitCode & " - " & $exit, "", "my@email.com", "", "") EndFunc Any help is greatly appreciated. I know it looks like a mess, so if anyone has ideas for tidying up the code as well, I'm all for it. Thanks, ~Felanor Check Out My ScriptsFile Property Management - Adjust a file's title, author, subject, etc. Link to comment Share on other sites More sharing options...
trancexx Posted December 21, 2008 Share Posted December 21, 2008 (edited) Hello Everyone, I am hoping to get some assistance finding the memory leak in my code. I've searched through it, but, alas, no luck finding it. I'm hoping that another few sets of eyes will help me find the error of my ways. When I run the program it starts off at about 9MB of memory used. As I leave it running it slowly builds. After running it for about 8 hours, it has jumped to 42MB of memory used. I had the program running for a few days and it was up to near 500MB, so I closed it down and restarted it. Here's the code, with company information taken out, of course. expandcollapse popup#Region;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=D:\HFWErrorParser.exe #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** Opt("TrayIconDebug",1) ; Includes Section #include <array.au3> #include <INet.au3> #include <File.au3> Dim $aFiles[1] Dim $oMyRet $hString = "" ; Production Directories $prndirectory = "\\SERVERNAMEHERE\c$\Upnotes\GENERIC\Auto_prn" $archivedirectory = "\\SERVERNAMEHERE\c$\Upnotes\GENERIC\reviewed\logs" ; Test Directories ; $prndirectory = "D:\PNR" ; $archivedirectory = "C:\ARCHIVE" _SendAlert("Error Log Monitoring Started", "The error log monitoring program has started on " & @ComputerName, "", "my@email.com", "", "") While 1 $hSearch = FileFindFirstFile($prndirectory & "\*.prn") ReDim $aFiles[1] $aFiles[0] = 0 While 1 $file = FileFindNextFile($hSearch) If @error then ExitLoop _ArrayAdd($aFiles,$file) $aFiles[0] += 1 WEnd For $z = 1 to $aFiles[0]-1 $datestamp = StringLeft($aFiles[$z],8) $aErrorFile = StringSplit(StringReplace(FileRead($prndirectory & "\" & $aFiles[$z]),@CRLF,"|"),"|") If Not FileExists($prndirectory & "\"& $datestamp & "HFWErrors.txt") Then $sString = $aErrorFile[6] & @CRLF & $aErrorFile[7] & @CRLF & $aErrorFile[8] & @CRLF Else $sString = "" EndIf For $x = 1 to $aErrorFile[0] If StringInStr($aErrorFile[$x],"*") Then $sString &= $aErrorFile[$x-2] & @CRLF & $aErrorFile[$x-1] & @CRLF & $aErrorFile[$x] If $x + 1 <= $aErrorFile[0] Then If StringInStr($aErrorFile[$x+1],".") Then $sString &= StringTrimLeft($aErrorFile[$x+1],18) EndIf $sString &= @CRLF & @CRLF EndIf Next FileWrite($prndirectory & "\"& $datestamp & "HFWErrors.txt",$sString) FileMove($prndirectory & "\" & $aFiles[$z],$archivedirectory & "\" & $aFiles[$z],9) $sString = "" Next Sleep(5000) _EmailLog() WEnd Func _EmailLog() $hSearch = FileFindFirstFile($prndirectory & "\*HFWErrors.txt") Dim $aFiles[1] $aFiles[0] = 0 While 1 $file = FileFindNextFile($hSearch) If @error then ExitLoop _ArrayAdd($aFiles,$file) $aFiles[0] += 1 WEnd $z = 1 While $z < $aFiles[0] _SendAlert("Henry Ford Errors", "Greetings. Attached is the daily generated log file of export errors.", $prndirectory & "\" & $aFiles[$z]) FileMove($prndirectory & "\" & $aFiles[$z], $prndirectory & "\sent\" & $aFiles[$z], 9) $z += 1 WEnd EndFunc Func _SendAlert($SUBJECT, $BODY, $ATTACH = "", $TO = "TO@email.com", $CC = "CC@email.com", $BCC = "BCC@email.com") _INetSmtpMailCom("smtpout.secureserver.net", "Support", "support@domain.com", $TO, $SUBJECT, $BODY, $ATTACH, $CC, $BCC, "login", "password", "80") EndFunc Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "Error", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($s_Body, "<") And StringInStr($s_Body, ">") Then $objEmail.HTMLBody = $s_Body Else $objEmail.Textbody = $s_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) If FileExists($S_Files2Attach[$x]) Then $objEmail.AddAttachment($S_Files2Attach[$x]) Else $i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x] SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf If $ssl Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf $objEmail.Configuration.Fields.Update $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf EndFunc;==>_INetSmtpMailCom Func OnAutoItExit() Switch @exitCode Case 0 $exit = "Natural Closing" Case 1 $exit = "Closed by Exit function" Case 2 $exit = "System Tray Exit" Case 3 $exit = "User Logoff" Case 4 $exit = "System Shutdown" EndSwitch _SendAlert("Error Log Monitoring Stopped", "The error log monitoring program has stopped on " & @ComputerName & "." & @CRLF & "Exit Code: " & @exitCode & " - " & $exit, "", "my@email.com", "", "") EndFunc Any help is greatly appreciated. I know it looks like a mess, so if anyone has ideas for tidying up the code as well, I'm all for it. Thanks, ~FelanorYou are building up search handles. Every 5 sec new one. Add FileClose($hSearch) to release it. Edited December 21, 2008 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now