AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Need a way to remove unneeded variables.

 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
Techrat



Joined: 09 Sep 2009
Posts: 10

PostPosted: Mon Nov 09, 2009 4:59 pm    Post subject: Need a way to remove unneeded variables. Reply with quote

In AHK you can create variables on the fly, but I see no way to remove them. You can set them to empty or blank but the variable name itself remains. In essence, still taking up memory.

I would like to see a 'KillVar' or 'Destroy' or 'Remove' command that could free up that memory on the fly. This would be especially helpful if 'true' arrays are ever implemented.

I use AHK to extract data from CSV files that originate fom databases, then parse the data to format and narrow the list and finally give the user a GUI face for a few choices to select from. Sometimes it becomes quite 'messy' to keep creating new variables, or reuse a bunch of temporary variables, especially if I've been using them like an array and the number of elements dont match.
Back to top
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Mon Nov 09, 2009 6:36 pm    Post subject: Reply with quote

Quote:
You can set them to empty or blank but the variable name itself remains. In essence, still taking up memory.


I don't see an issue with the variable name itself, taking up memory. As you state, you know that you can clear the variable value or set it back to 0 as needed, what is the significance of killing the Variable namr itself?

If you kill the script, you kill the variable...

If you have the script up, you have the variable with a memory location, used or unused, it is still registered upon script initialzaion.



Quote:
I would like to see a 'KillVar' or 'Destroy' or 'Remove' command that could free up that memory on the fly
This seems equivilant to Variable := "" as the variable name itself takes up memory, weather or not it contains a value in the script.
Back to top
View user's profile Send private message
fincs



Joined: 05 May 2007
Posts: 1160
Location: Seville, Spain

PostPosted: Mon Nov 09, 2009 9:42 pm    Post subject: Reply with quote

Assigning an empty string to a variable only deletes the memory when it is bigger than 4 kB for performance reasons.
VarSetCapacity(var, 0) actually deletes the memory used by the variable.
Additionally AutoHotkey reserves allocate-only memory for a variable if its initial size is not bigger than 64 bytes (SimpleHeap), of course it changes to malloc'ed memory if you assign it a bigger string.
I think I should take a break from working with the AHK source Laughing
_________________
fincs
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]
Back to top
View user's profile Send private message
Carcophan



Joined: 24 Dec 2008
Posts: 1308
Location: :noitacoL

PostPosted: Mon Nov 09, 2009 10:55 pm    Post subject: Reply with quote

Quote:
I think I should take a break from working with the AHK source


Disagree!
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7293
Location: Australia

PostPosted: Tue Nov 10, 2009 3:32 am    Post subject: Reply with quote

fincs wrote:
VarSetCapacity(var, 0) actually deletes the memory used by the variable.
Technically it only frees the memory used by the contents of the variable. It does not free the variable itself; i.e. the "Var" structure which holds the name, length, capacity, method of allocation, cached binary number, attributes etc. (I think the Var structure is 32 bytes plus the size of the name, but I'm too lazy to confirm.)

FYI, most of this has been discussed before, but not since objects/arrays were introduced into AutoHotkey_L. Arrays within objects should use less memory on average than typical AutoHotkey pseudo-arrays. Items can be removed; currently doing so frees any associated strings (text) and allows the memory of the item itself to be later reused. If an object has excess memory (e.g. you've added and removed 1000 items), _SetCapacity can be used to shrink it.

There are also other, more important reasons to use arrays/objects...
Back to top
View user's profile Send private message Visit poster's website
fincs



Joined: 05 May 2007
Posts: 1160
Location: Seville, Spain

PostPosted: Tue Nov 10, 2009 9:14 pm    Post subject: Reply with quote

Lexikos, you're right. When I wrote that reply I meant to say the contents but failed horribly at doing so.
I should really stop trying to do things when I'm tired.
_________________
fincs
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Jan 02, 2010 2:02 pm    Post subject: Reply with quote

I would really love to have a delete variable feature!

I wrote a script that adds lots of hotkeys to an application. It starts at system boot and waits for that application window's class to activate.

There can be multiple processes running the application simultaneously, so the script has to create a large set of variables to store context for each process when that process's window is not active. These context variables have dynamic names like SelectedFeatureFlag%HWND%.

I have a timer that runs every x minute to check if all of the known processes for the application still exist. If any don't the timer routine does SetVarCapacity(var%HWND%, 0) for the unneeded context variables.

This works well, but if my computer is up for a week there can be 100s of these stale, empty variables left around. I realize they do not cause a performance issue, but they sure are annoying when I need to check a live process's context variables with View Variables and their contents.
Back to top
Guest






PostPosted: Thu Mar 04, 2010 6:13 pm    Post subject: Reply with quote

I agree, this feature is necessary. I generate large (as in hundreds of thousands) array entries as I parse data with autohotkey and when I am done all this memory is still "committed" in virtual memory even though I set the variables I am done with to "". I am running into issues where my virtual memory is exhausted and autohotkey can not create or add to any variables it has. A feature to delete this "committed" memory would be great.
Back to top
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Thu Mar 04, 2010 7:02 pm    Post subject: Reply with quote

Anonymous wrote:
A feature to delete this "committed" memory would be great.
Reload Wink
Lexikos wrote:
FYI, most of this has been discussed before,
Could you provide a link to the relevant thread? I've yet to see a convincing argument for the necessity of this feature, but there seems to be a vocal minority who are unable to script without it.
Back to top
View user's profile Send private message Visit poster's website
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Thu Mar 04, 2010 9:30 pm    Post subject: Reply with quote

This seems related: EmptyMem()
_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Lexikos



Joined: 17 Oct 2006
Posts: 7293
Location: Australia

PostPosted: Fri Mar 05, 2010 4:22 am    Post subject: Reply with quote

jaco0646 wrote:
Could you provide a link to the relevant thread?
I don't recall where it was, but there probably wasn't anything important mentioned that hasn't been mentioned here.
Quote:
I've yet to see a convincing argument for the necessity of this feature,
I agree, but then no such argument is possible from my perspective. It just seems like a poor workaround for the lack of proper arrays.
Back to top
View user's profile Send private message Visit poster's website
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Fri Mar 05, 2010 4:59 am    Post subject: Reply with quote

Lexikos wrote:
It just seems like a poor workaround for the lack of proper arrays.
I agree with Lexikos - and since he can't properly edify himself, I will. IMO, object/array support is the best enhancement to AHK since I started using it. Great work Lexikos - this is something that, IMO, needs to be included in the standard release of AHK. It would solve many issues, including this thread.
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group