Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Help with a memory leak..

$
0
0
Hi Guys,

I've been tearing my hair out over this one. Cant figure out where the leak is. When I run my script it will constantly increase in memory usage until it eventually crashes. When I watch the memory usage of autoit in the task manager there is no increase in usage but the overall usage drops as soon as i close my script.

Most of the code is very simple and by commenting out a single line I can stop the leak.. sadly this lines very important.

Heres the function i'm running which seems to be the problem. Its a modified version of a _tesseract.au3 function which simply captures an area of a window to a file and I've added code to rotate this image by 90 degrees before its saved.

EDIT: The memory usage increases quite rapidly about 12MB/min, the function is being called repeatedly in quick succession.

[ autoit ]         
Func CaptureToTIFF($win_title = "", $win_text = "", $ctrl_id = "", $sOutImage = "", $scale = 1, $left_indent = 0, $top_indent = 0, $right_indent = 0, $bottom_indent = 0) Local $hWnd, $hwnd2, $hDC, $hBMP, $hImage1, $hGraphic, $CLSID, $tParams, $pParams, $tData, $i = 0, $hImage2, $pos[4] Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) Local $giTIFColorDepth = 24 Local $giTIFCompression = $GDIP_EVTCOMPRESSIONNONE ; If capturing a control if StringCompare($ctrl_id, "") <> 0 Then $hwnd2 = ControlGetHandle($win_title, $win_text, $ctrl_id) $pos = ControlGetPos($win_title, $win_text, $ctrl_id) Else ; If capturing a window if StringCompare($win_title, "") <> 0 Then $hwnd2 = WinGetHandle($win_title, $win_text) $pos = WinGetPos($win_title, $win_text) Else ; If capturing the desktop $hwnd2 = "" $pos[0] = 0 $pos[1] = 0 $pos[2] = @DesktopWidth $pos[3] = @DesktopHeight EndIf EndIf ; Capture an image of the window / control if IsHWnd($hwnd2) Then WinActivate($win_title, $win_text) $size=WinGetClientSize($win_title,$win_text) $hBitmap2 = _ScreenCapture_CaptureWnd("", $hwnd2, 0, 0, -1, -1, False) Else $hBitmap2 = _ScreenCapture_Capture("", $size[0], 0, 0, $size[1], False) EndIf ;commented out and moved to start of code for debug _GDIPlus_Startup () $hImage2 = _GDIPlus_BitmapCreateFromHBITMAP ($hBitmap2) $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, ($pos[2] * $scale) - ($right_indent * $scale), ($pos[3] * $scale) - ($bottom_indent * $scale)) _WinAPI_ReleaseDC($hWnd, $hDC) $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0 - ($left_indent * $scale), 0 - ($top_indent * $scale), ($pos[2] * $scale) + $left_indent, ($pos[3] * $scale) + $top_indent) ;removed tiff parameters settings for debug ; Save TIFF and cleanup $hImage3 = _GDIPlus_BitmapCreateFromGraphics(_GDIPlus_ImageGetHeight($hImage1), _GDIPlus_ImageGetWidth($hImage1), $hGraphic) $hGraphic3 = _GDIPlus_ImageGetGraphicsContext($hImage3) $matrix = _GDIPlus_MatrixCreate() _GDIPlus_MatrixRotate($matrix, -90) _GDIPlus_GraphicsSetTransform($hGraphic3, $matrix) _GDIPlus_GraphicsDrawImage($hGraphic3, $hImage1, -_GDIPlus_ImageGetWidth($hImage1), 0) _GDIPlus_ImageSaveToFile($hImage3, $sOutImage);, $CLSID, $pParams) ;replaced the below function call with code above for rotation to prevent nested starting of gdi plus ;rotate_image($sOutImage) _GDIPlus_MatrixDispose($matrix) _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_ImageDispose($hImage3) _GDIPlus_GraphicsDispose ($hGraphic) _GDIPlus_GraphicsDispose ($hGraphic3) _WinAPI_DeleteObject($hBMP) sleep(100) ;_GDIPlus_Shutdown() EndFunc

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>