Colyn1337 Posted May 30, 2012 Share Posted May 30, 2012 (edited) Hello Community! I'm working on a script which uses WMI to expose BIOS info. The script works, but it does not release the memory it used to execute the object creation and query. The script will continually wire more and more memory everytime the case is called. As a work around, I've stored the result of the query in a variable in case it's called again, but I would like to figure out how to manage the memory better. The code itself is for HP Bios, so it's not likely to work on a non HP machine. #include <Constants.au3> Opt("TrayMenuMode", 1) TraySetState() $ItemSerial = TrayCreateItem("Serial Number") While 1 $msg = TrayGetMsg() Select Case $msg = $ItemSerial TrayItemSetState($ItemSerial, $TRAY_UNCHECKED) If $Serial = "" Then $objWMI = ObjGet("winmgmts:" & @ComputerName & "rootHPInstrumentedBIOS") If $objWMI = ("") Then BasicSet() $colItems = $objWMI.ExecQuery("SELECT * FROM HPBIOS_BIOSString", "WQL", "wbemFlagReturnImmediately" + "wbemFlagForwardOnly") If IsObj($colItems) Then For $objItems In $colItems If $objItems.Name = "Serial Number" Then $Serial = $objItems.Value EndIf Next EndIf EndIf MsgBox(0, "Serial Number", "Serial Number is " & $Serial, 30) $objWMI = 0 ; This deletes the object For simplicity I pulled out one example from the script, my apologies if something is missing. Edited May 30, 2012 by Colyn1337 Link to comment Share on other sites More sharing options...
trancexx Posted May 30, 2012 Share Posted May 30, 2012 First thing to see is that you are calling ExecQuery method wrong. Flags are meant to be integers and you are passing strings. Those strings are then turned into numbers internally and the result of that conversion is integer of zero value. If I would then look what flag has value of 0, I would see it's wbemFlagBidirectional. The description for that flag is: "Causes WMI to retain pointers to objects of the enumeration until the client releases the enumerator".Don't over-complicate simple stuff. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Colyn1337 Posted May 30, 2012 Author Share Posted May 30, 2012 Thanks for the reply, and the correction!! I've changed the script so that integers are used instead of strings, and I've toyed with using other iFlags as well as not using any at all. I still can't get it to release memory... When the script first starts it wires about 2200kb, when executing the query it jumps to about 3000kb and only drops to 2900kb after its done and the object is deleted... Is that just normal behavior, or is there a way to get it back down to about where it started? Link to comment Share on other sites More sharing options...
trancexx Posted May 30, 2012 Share Posted May 30, 2012 Numbers are irrelevant. There are several internal mechanisms (both AutoIt's and Windows') affecting the memory consumption. You don't have to worry about them. Generally speaking, memory leak is not about memory consumption, it's about growth of memory consumption on repetitive tasks. To test if something leaks simply call it in a loop and check if memory consumption would constantly grow. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Colyn1337 Posted May 30, 2012 Author Share Posted May 30, 2012 Thank you very much for your time and your explanation! It's truly appreciated. 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