Jump to content

How to delete variables after using assign()


 Share

Recommended Posts

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

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().

:D

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

  • Moderators

rbhkamal,

running these scripts for a week or so

Coooooo! :huggles:

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. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 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

And you thought Assign()/Eval() SIMPLIFIED the script?! :D

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().

:huggles:

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

And you thought Assign()/Eval() SIMPLIFIED the script?! :D

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...