lowbattery Posted December 5 Posted December 5 (edited) I have a monster script of a program. About 35,000 lines. In a given situation, the memory starts increasing as a certain (complex) operation is performed. It goes from 150mb eventually to about 1,500mb over the span of a few hours. As far as I'm aware, I'm not deliberately storing data that I'm processing in memory. After I process it, I dump it into a file and move onto the next task. But there are so many moving parts, that it's hard for me to pinpoint what's causing the memory growth. So is there any way to check what variables in a program are growing, or where a potential leak is coming from? Edited December 5 by lowbattery
Nine Posted December 5 Posted December 5 (edited) There is no easy way to perform what you want to achieve. But you can quite easily find WHERE the leak is happening. You will need to log at various strategic places (e.g. beginning and end of a function, beginning and end of a task, etc) the result of ProcessGetStats() (see help file for more details). As an example here, you see that by not closing the file makes the script grow rapidly in memory size. Instead of writing to the console, write it in a log file, put some timestamp and location within the script and you will find where the memory starts growing. Example() Func Example() Local $aMemory = ProcessGetStats(), $hFile ConsoleWrite("WorkingSetSize: " & $aMemory[0] & "/ PeakWorkingSetSize: " & $aMemory[1] & @CRLF) For $i = 1 To 1000 $hFile = FileOpen("Torus.jpg") ;FileClose($hFile) Next $aMemory = ProcessGetStats() ConsoleWrite("WorkingSetSize: " & $aMemory[0] & "/ PeakWorkingSetSize: " & $aMemory[1] & @CRLF) EndFunc ;==>Example ps. see Debug Management UDF in help file to support logging into a file Edited December 5 by Nine pixelsearch and Musashi 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
KaFu Posted December 5 Posted December 5 (edited) Look in the Task Manager for Details. If not visible already, you can add GDI-Objects and Handle count for the process. Both are notorious (at least for me) regarding memory leaks. If the counter goes up all the time of either one, you have a first indication where to look (GDI resources not cleaned up properly, file or pipe handles orphaned). Also I trace such leaks by first commenting out the time consuming parts, and if the mem usage goes up fast after that, comment out again large sections to narrow the search down. Edited December 5 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
argumentum Posted December 6 Posted December 6 https://www.autoitscript.com/forum/index.php?showtopic=197259&view=findpost&p=1414754 may aid KaFu troubleshooting ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
rudi Posted December 9 Posted December 9 Two points that I have stumbled over several times are 1) recursive nested file queries (filefindfirstfile, filefindnextfile), for which I forgot to close the search handle "local $s=FileFindFirstFile()" with fileclose($s) before leaving the loop, once a directory level was done, and 2.) reading the output of commandline tools, where I missed to close the stream: $pid=Run(“C:\temp\myprogram.exe”,@TempDir,@SW_HIDE,$STDERR_MERGED) ... StdioClose ( $pid) Earth is flat, pigs can fly, and Nuclear Power is SAFE!
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