rbhkamal Posted January 20, 2010 Share Posted January 20, 2010 Hi, Some of my scripts use the assign() function to create new variables. After running these scripts for a week or so, they run the system out-of-memory. I looked around and I think I found the problem and I'm afraid its a "design" issue but decieded to see if there is a workaround before redesiging the whole script. Below is a script which ,I think, reproduces my problem. As you can see the memory jumps to 50mb immediately when running it. So my question is, is it possible to delete these vars that are not being used anymore? Thanks, RK $count = 0 $varName = "" While True $varName = "testing" & $count Assign($varName, $count) ConsoleWrite($varName & " = " & Eval("testing" & $count) & @CRLF) Assign( $varName , '' ) $count += 1 WEnd "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 20, 2010 Share Posted January 20, 2010 What's the point of all those unique variable names? That script accomplishes exactly nothing other than sucking up resources. I realize it's probably not your actual script, but it doesn't illustrate any use of the variables at all. The design problem is the fact that you used Assign()/Eval() at all! Why did you do that? This is the side of it to be addressed. The fix is to recode it without Assign()/Eval(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 20, 2010 Moderators Share Posted January 20, 2010 rbhkamal, running these scripts for a week or soCoooooo! Perhaps a rewrite of the code to prevent the use of Assign might be a better option. This code produces the same output as yours and does not need Assign: $count = 0 $varName = "" While True $varName = "testing" & $count ConsoleWrite($varName & " = " & $count & @CRLF) $count += 1 WEnd Output: Yours: testing0 = 0 testing1 = 1 testing2 = 2 testing3 = 3 testing4 = 4 testing5 = 5 testing6 = 6 testing7 = 7 testing8 = 8 testing9 = 9 Mine: testing0 = 0 testing1 = 1 testing2 = 2 testing3 = 3 testing4 = 4 testing5 = 5 testing6 = 6 testing7 = 7 testing8 = 8 testing9 = 9 If you let us see the code we might be able to help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rbhkamal Posted January 20, 2010 Author Share Posted January 20, 2010 (edited) Your are correct, however, rewriting everything will take few weeks to finish and I simply don't have that time. The original script is very complicated and the assign/evals are spread-out across it, the script I wrote simplifies things so you guys can help me out (if possible) There is a client/server libraries (written in autoit) that enables two scripts to register and execute actions on a remote computer and transfer files across the network. The actions use these dynamic variables to mainly store the function name and the parameters which it accepts (could be a 100 params). The function name and params are then used together to execute the action using call() [Edit] I'm planning to post these libraries here after I take permission from the boss Edited January 20, 2010 by rbhkamal "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 20, 2010 Share Posted January 20, 2010 And you thought Assign()/Eval() SIMPLIFIED the script?! Are you (or whoever wrote this) array-phobic. That's usually what drives people to mess around with Assign()/Eval() at all. With arrays, scripting dictionaries (COM associative arrays), read/write files, etc. you can get the work done in a much more maintainable way. You could also consider adding your own UDFs like _AssignSim() and _EvalSim() to handle the data without the silliness. For example, those UDFs might keep all the variables and their values in a file (or even an SQLite DB). No system resources are sucked up by continued use then. Then all you have to do is Find/Replace every instance of "Assign(" with "_AssignSim(" to give it a short term fix. The long term fix is still a rewrite without any Assign()/Eval(). Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
rbhkamal Posted January 20, 2010 Author Share Posted January 20, 2010 And you thought Assign()/Eval() SIMPLIFIED the script?! LOL ... I think I'm going with your short term fix permanently. "When the power of love overcomes the love of power, the world will know peace"-Jimi Hendrix 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