Mateo Posted January 1, 2021 Share Posted January 1, 2021 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 Link to comment Share on other sites More sharing options...
Mateo Posted January 1, 2021 Author Share Posted January 1, 2021 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) Link to comment Share on other sites More sharing options...
Network_Guy Posted January 1, 2021 Share Posted January 1, 2021 (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, 2021 by Network_Guy Link to comment Share on other sites More sharing options...
Nine Posted January 1, 2021 Share Posted January 1, 2021 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 “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 Link to comment Share on other sites More sharing options...
Mateo Posted January 3, 2021 Author Share Posted January 3, 2021 Thank you very much! I'll check it out Link to comment Share on other sites More sharing options...
Mateo Posted January 3, 2021 Author Share Posted January 3, 2021 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 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