Jump to content
Mateo

High resource consumption

Recommended Posts

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
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
Posted (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 by Network_Guy

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...