chrishavenga Posted November 16, 2011 Share Posted November 16, 2011 I experience a similar problem as user MDCT.I created an app using mostly standard scripts to look for PDF files in a directory and print them to the default printer.The app also uses the default PDF application (Foxit Reader in my case).The problem is that after each loop the app builds up memory.Is there a way to free up the memory or is there something that I can do differently in the code?PC Specs of two similar PCs I tested on:Windows XP (Service Pack 3)Intel Pentium 4, 3.00GHz, 1GB RAMexpandcollapse popup$i = 1 While $i > 0 Sleep(1000) If FileExists("*.pdf") Then ; [This message can later be logged in a text file] ; MsgBox(4096, "PDF File(s)", "PDF Files Exists") ; [Shows the filenames of all files in the current directory.] $search = FileFindFirstFile('*.pdf') ; [Check if the search was successful] If $search = -1 Then ; [This message can later be logged in a text file] ; MsgBox(0, "Error", "No PDF files were found") ; Exit EndIf While 1 ; [Searches for the next PDF file] $file = FileFindNextFile($search) If @error Then ExitLoop ; [This message can later be logged in a text file] ; MsgBox(4096, "File:", "C:\PDFPrintSpool\" & $file) ; [Assign the Full path of the PDF file to variable] $PDFFileURL = "C:\PDFPrintSpool\"& $file ; [Prints the PDF file when found] shellexecuteWait($PDFFileURL,"","","print") ; [Call to close Foxit Reader] ProcessClose("Foxit Reader.exe") ; [Delete the PDF file that was last printed] FileDelete($PDFFileURL) WEnd ; [Close the search handle] FileClose($search) Else ; [This message can later be logged in a text file] ; MsgBox(4096,"Error", "No PDF files were found") EndIf Sleep(1000) WEnd Link to comment Share on other sites More sharing options...
chrishavenga Posted November 16, 2011 Author Share Posted November 16, 2011 A work-around fix for the problem, I created. (Yoda!) Another app that runs as a loop (a.k.a. my app service) calling the original Auto PDF printer app. No stealing of memory, anymore. Yay! (Still would like to know for future reference how to free up memory used by AutoIt... ) Link to comment Share on other sites More sharing options...
Mat Posted November 16, 2011 Share Posted November 16, 2011 Two things: The way I usually go about this is to comment out lines one by one so that I know exactly what lines are causing the problem. Then you can look at how to solve it. EmptyWorkingSet (google the forum for more info) AutoIt Project Listing Link to comment Share on other sites More sharing options...
MDCT Posted November 16, 2011 Share Posted November 16, 2011 (edited) Yes. You can free the RAM by using this: Func _ReduceMemory($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFunc ;==>_ReduceMemory Just use it _ReduceMemory() to reduce the current script, you can use it on other processes. However, it will just hide a problem if there's a memory leak. Edit: Oops, Mat beat me to it. Edited November 16, 2011 by MDCT Link to comment Share on other sites More sharing options...
chrishavenga Posted November 16, 2011 Author Share Posted November 16, 2011 Thank you for the replies! I am happy for now with the fix I implemented. In the next version of the app I will definitely implement the solutions above. 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