1

I have an ahk script I use to enable the Printer button on a Crystal Reports dialog that for what ever reason is not enabled by default when used in Server 2008 R2. Anyways... the issue I am having is the process when running continues to stack memory each cycle. Its not like I am storing any contents to a variable that happens to not get cleared. What in this process uses memory resources that don't get released and is there anything I can implement to prevent this from happening?

You can see in this listing that the private memory just grows as usage goes on. I ended up having it initiate about 5 times and it went from about 1000k to 2000k.

The top entry is my test version I converted from WinWaitActive that was causing unnecessary CPU usage.

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
 58       8     2312       6216    68     0.62   7828 showprinterbutton
 55       8     1788       5508    67    32.39   6840 ShowPSPrinter
 57       8     1864       6028    79    33.12   7184 ShowPSPrinter
 55       8     1396       5084    67     1.29   7604 ShowPSPrinter
 55       8     1796       5536    67    36.36   7856 ShowPSPrinter
 55       8     1772       5444    67    37.27   9848 ShowPSPrinter
 55       8     1740       5424    67    26.33  10300 ShowPSPrinter
 55       8     1396       4992    67     0.84  11348 ShowPSPrinter
 55       8     1396       5024    67     1.14  11460 ShowPSPrinter
 55       8     1736       5604    67   355.93  11676 ShowPSPrinter
 55       8     1396       4984    67     1.06  13364 ShowPSPrinter
 55       8     1396       5132    67     0.81  13516 ShowPSPrinter
 72       9     2048       6500    73    66.36  14072 ShowPSPrinter
 55       8     1792       5504    67    59.92  15736 ShowPSPrinter
 55       8     1400       4960    67     0.61  16340 ShowPSPrinter
 57       8     1496       5848    79     0.98  18516 ShowPSPrinter
 57       8     1500       5404    79     0.98  19048 ShowPSPrinter
 55       8     1400       5000    67     0.51  22020 ShowPSPrinter

Here is the script contents I have that is then compiled to run as an EXE.

; Version: 1.2
; Dated: 03/31/2015 - Created
; Description: Enable a watch for page setup dialog and activate the print button for crystal reports


; Only allow one instance to run
#SingleInstance force 

; Run with out a tray icon
#NoTrayIcon 

; Getting loose with not requiring direct title menu values
SetTitleMatchMode, RegEx

; Start active watch for quick post menu
WaitForPS:
WinWait,Page Setup
{
    Control,Show,,Button8,Page Setup,(optimize for screen display)
    GoSub WaitForPS
}


; End of Script...
ATek
  • 815
  • 2
  • 8
  • 20

1 Answers1

2

Right after the moment the window appears and the loop ran one time, WainWait immediately continues to the next statement because the window already exists, enables the control, and recursively invokes the loop again (gosub), so the code allocated for example 100 stack frames per second thus eventually exhausting the call stack.

Instead use an indefinite loop and before continuing wait for the window to close:

Loop
{
    WinWait,Page Setup
    Control,Show,,Button8,Page Setup,(optimize for screen display)
    WinWaitClose
}
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • nailed it, thanks much! now I can deploy this to production and not stress over it. – ATek Aug 07 '15 at 17:08