Mateo 0 Posted January 1 Hi, I have the following code, I can not understand why the amount of RAM it takes all the time increases! I tried to test it from many directions and failed and I would really love help !! Thank you #include <constants.au3> Func _GetActiveSSID() Local $line, $pid = Run(@ComSpec & " /c " & 'netsh wlan show interfaces', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 If ProcessExists($pid) Then $line = StringStripWS(StdoutRead($pid, "peek=True"), 4) If @error Then Return("Error") If StringInStr($line, "SSID") Then $line = StringTrimLeft($line, StringInStr($line, "SSID")+6) Return(StringTrimRight($line, StringLen($line)-StringInStr($line, "BSSID")+2)) ElseIf StringInStr($line, "disconnected") Then Return("None") EndIf Else Return("Process Closed") EndIf WEnd EndFunc While 1 MsgBox(0, "SSID", _GetActiveSSID(), 0.5) Sleep(500) WEnd Share this post Link to post Share on other sites
Mateo 0 Posted January 1 Just now, Mateo said: While 1 MsgBox(0, "SSID", _GetActiveSSID(), 0.5) Sleep(500) WEnd It should be noted that the point in this code snippet is to check if it really is this function that is consuming the RAM (it's a big code, but really the problem is here) Share this post Link to post Share on other sites
Network_Guy 8 Posted January 1 (edited) using return("string") like this bugging the script it should return variable only . try use msgbox or console write instead. and i recommend using processwaitexit method to get the output std than the loop method in your case .exp #include <constants.au3> Func _GetActiveSSID() Local $line, $pid = Run(@ComSpec & " /c " & 'netsh wlan show interfaces', "", @SW_HIDE, $STDERR_CHILD+ $STDOUT_CHILD ) ProcessWaitClose($pid) $line = StringStripWS(StdoutRead($pid), 4) If @error Then ConsoleWrite("Error") If StringInStr($line, "SSID") Then $line = StringTrimLeft($line, StringInStr($line, "SSID")+6) ConsoleWrite(StringTrimRight($line, StringLen($line)-StringInStr($line, "BSSID")+2)) ElseIf StringInStr($line, "disconnected") Then ConsoleWrite("None"&@CRLF) EndIf StdioClose($pid) EndFunc While 1 MsgBox(0, "SSID", _GetActiveSSID(), 0.5) Sleep(500) WEnd Edited January 1 by Network_Guy Share this post Link to post Share on other sites
Nine 921 Posted January 1 The major problem is that line (in fact there is 3 problems with that line) : $line = StringStripWS(StdoutRead($pid, "peek=True"), 4) 1) Second parameter of StdoutRead should be a boolean whereas "peek=True" is a string. 2) Since that string is converted to True, you are always peeking and never grabbing (your memory leak) 3) StringStripWS erases the @error of the StdoutRead. You will never find an @error that way... Here the correct way to get the info needed : #include <constants.au3> While 1 MsgBox(0, "SSID", _GetActiveSSID(), 0.5) Sleep(500) WEnd Func _GetActiveSSID() Local $line, $pid = Run(@ComSpec & " /c " & 'netsh wlan show interfaces', "", @SW_HIDE, $STDERR_MERGED) ProcessWaitClose($pid) $line = StdoutRead($pid) If @error Then Return "Error" $line = StringStripWS($line, 4) If StringInStr($line, "SSID") Then $line = StringTrimLeft($line, StringInStr($line, "SSID") + 6) Return StringTrimRight($line, StringLen($line) - StringInStr($line, "BSSID") + 2) ElseIf StringInStr($line, "disconnected") Then Return "None" EndIf Return "Not found" EndFunc ;==>_GetActiveSSID Not much of a signature, but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Tool to search content in au3 files Date Range Picker Sudoku Game 2020 Overlapped Named Pipe IPC x64 Bitwise Operations Fast and simple WCD IPC GIF Animation (cached) Share this post Link to post Share on other sites
Mateo 0 Posted January 3 Thank you very much! I'll check it out Share this post Link to post Share on other sites
Mateo 0 Posted January 3 Func _ReduceMemory() Local $aReturn = DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1) If @error = 1 Then Return SetError(1, 0, 0) EndIf Return $aReturn[0] EndFunc I finally used this code. He does the job excellently. Many thanks to the helpers Share this post Link to post Share on other sites