Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Deleting a variable


  • Please log in to reply
14 replies to this topic
jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010
Ok so I was reading through the gdi (Wow this is just wow.... Awesome stuff) but anyways, I just was seeing the delete variable with the gdi (Specifically I was looking at his pen) and I was just wondering, can you deleted a normal variable you make in AHK...

Like lets say I were to assign:

MyVarTakingSpace := 10

Could I use something to delete that and save memory space? I was looking for a function in AHK that did this but I didn't see one. I was just wondering. Thanks.

Murx
  • Guests
  • Last active:
  • Joined: --
MyVarTakingSpace := ""
??

jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010

MyVarTakingSpace := ""
??


Does that actually erase the variable from taking memory? I was thinking about that but didn't know for sure because I never worked with any other kind of programming.

sinkfaze
  • Moderators
  • 6367 posts
  • Last active:
  • Joined: 18 Mar 2008
VarSetCapacity():

VarSetCapacity(MyVarTakingSpace,0)


jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010

VarSetCapacity():

VarSetCapacity(MyVarTakingSpace,0)


That is more what I was looking for. Thanks. What if I want to recreate the variable later in the script though? Just reset it with the same function?

Example:

VarSetCapacity(MyVarTakingSpace,0)
;elsewhere
VarSetCapacity(MyVarTakingSpace)


  • Guests
  • Last active:
  • Joined: --
Overview...
[*:2l4wis6z]You cannot currently completely DELETE a variable
[*:2l4wis6z]You can CLEAR a vars contents with...

var=
;//...or...
var:=""
[*:2l4wis6z]You can also more fully clear a vars contents/memory allocation with...

VarSetCapacity(var, 0)
[*:2l4wis6z]You do not need to un-VarSetCapacity() to use the var again, just use it...

var=newvalue
...VarSetCapacity() can be used to fully clear a var or to pre-allocate a specific size to a var, but you don't need to "undo" it if you use it to clear a var...

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
Here is a thread created about 6 hours before this one: Is there any way to deallocate a global variable? tank gives a succinct answer.

  • Guests
  • Last active:
  • Joined: --
I did not see the other thread, but I covered every possibility in my answer...

tank gives a succinct answer.

...I prefer verbose answers than succinct ones...with a snide remark of "why does it matter?"...it matters cuz you should be able to delete vars fully...

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
Your answer is excellent. The purpose of my reply was to point out that a quick forum search often prevents the creation of redundant threads.

Since you prefer verbose answers, would you expound on your response to tank? :wink: He wrote, "why does it matter?" and you responded, "it matters cuz you should be able to delete vars fully." That is circular logic. The question, "Why should you be able to delete vars fully?" is not answered by saying, "Because you should be able to delete vars fully."

All sarcasm aside, is there a technical need for this?

  • Guests
  • Last active:
  • Joined: --

That is circular logic.

...I think my brain exploded on that one...lol...

...is there a technical need for this?

...maybe for cleaning up ListVars? Knowing it's "really" gone? Just for having the option/power to do it? I have an include file that, for some reason, poisons the Global var list with temp vars & I have to jump thru hoops to avoid creating visible useless/temp Global vars...so being able to explicitly delete them might help or make cleaning up the list easier...

  • Guests
  • Last active:
  • Joined: --
I did do a forum search but it didn't come up with that topic because he named it deallocating (Which was closer to deleting a variable then this topic of actually deleting one, but I didn't think of it) rather then delete which I didn't see come up. Sorry. :?

-jpjazzy

jaco0646
  • Moderators
  • 3165 posts
  • Last active: Apr 01 2014 01:46 AM
  • Joined: 07 Oct 2006
I understand there are several reasons why people ask about deleting variables; but there is no technical need for it that I've ever seen, which I think is what tank was getting at (in his typical manner).

Begging the question
Posted Image
:lol:

  • Guests
  • Last active:
  • Joined: --
Haha... Must admit that's an epic picture.

Guess this is true since variables can be reassigned just was wondering though after reading the gdi tutorial and saw the delete pens/other variables.

  • Guests
  • Last active:
  • Joined: --
not only programs, its also true in OS
when u delete a file or something, it doesnt really delete it, it just hides it

jpjazzy
  • Members
  • 800 posts
  • Last active: Dec 17 2014 07:22 AM
  • Joined: 16 Feb 2010

not only programs, its also true in OS
when u delete a file or something, it doesnt really delete it, it just hides it


True... didn't really think about that.... GetDataBack Or some other hard disk recovery is a perfect example. You can get them back so long as nothing has been overwritten which is the same case in the programming I suppose. :)