• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Quick Question!

Status
Not open for further replies.
Level 4
Joined
Jan 27, 2008
Messages
72
Hey guys, I'm wondering about a few things related to variables.

If you are using a player variable named Blue, and if there is a trigger that sets Blue = player 1 (red), then will this setting be destroyed if you later turn off this trigger?

If not, how do you destroy a player variable?

Thanks,
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
That is indeed true.

However, he is not destroying it. He is emptying it instead ^.^
A variable after all, is nothing more then a pointer reference towards a handle (object).

wikipedia said:
Objects allocated from the heap must be reclaimed—especially when the objects are no longer needed. In a garbage-collected language (such as C#, Java, and Lisp), the runtime environment automatically reclaims objects when extant variables can no longer refer to them. In non-garbage-collected languages, such as C, the program (and the programmer) must explicitly allocate memory, and then later free it, to reclaim its memory. Failure to do so leads to memory leaks, in which the heap is depleted as the program runs, risks eventual failure from exhausting available memory.

When a variable refers to a data structure created dynamically, some of its components may be only indirectly accessed through the variable. In such circumstances, garbage collectors (or analogous program features in languages that lack garbage collectors) must deal with a case where only a portion of the memory reachable from the variable needs to be reclaimed.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
He is not destroying it, he is emptying it ^.^
A variable after all, is nothing more then a pointer reference to the handle.

But if u try to reference it when its empty, the thread will crash, correct? :\
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
Indeed it will Arhowk, indeed it will :D

So he probably needs to make sure not to use it when it is referenced to null (nothing).
Most programming languages have protection for checking against a variable containing null.
Or even when using it in function calls. (Which eventually can lead to bottlenecks when debugging your code though).
A shame that Jass doesn't have this protection. I could think of some useful scenario's in this case :(
 
Status
Not open for further replies.
Top