• 🏆 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!

Do I need to destroy a variable after use?

Status
Not open for further replies.
Level 7
Joined
Jul 1, 2008
Messages
1,025
Hi, I am abit confused, I have been told you need to store data in variables to stop it leaking and causing lag/crashes etc, so for example if you are selecting every unit owned by player of type, you need to store it in a variable. Thats fine, I understand that.

But do I then need to destroy that variable after I've used it to stop it leaking? And if so do I need to do this for all variables types?
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
If your variable is local (done in JASS Script), you must null it if it's a handle (Units, Locations, etc).

Example;
  • Custom script: local unit u = GetTriggerUnit()
  • Custom script: call KillUnit(u)
  • Custom script: set u = null
Only null this if you're creating a local variable (Handle-type).
Variables such as Integer/Real, does not need to be nulled as they are not handles.

But I can't say for sure should we first null location, or destroy them first.
Either way, it'll work (I think).
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
If your variable is local (done in JASS Script), you must null it if it's a handle (Units, Locations, etc).

Example;
  • Custom script: local unit u = GetTriggerUnit()
  • Custom script: call KillUnit(u)
  • Custom script: set u = null
Only null this if you're creating a local variable (Handle-type).
Variables such as Integer/Real, does not need to be nulled as they are not handles.

But I can't say for sure should we first null location, or destroy them first.
Either way, it'll work (I think).

Globals need to be nulled too, it's just that nobody does it.

You need to destroy the location before nulling it, because nulling removes the reference to the location.

Ok I don't really understand all this null variable stuff, I was never pro at triggers but I will ask my triggerer friend if he can have a look at this thread and get rid of any leaks in our map, hope he will understand!

As far as I know, variables of handle type point to the address of data instead of holding it (which would be logical, because handles are structures). Because they're being referenced by variables, a handle will not be recycled until all of the references are gone. By nulling a variable, you remove the reference and the handle is free to be recycled.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Globals need to be nulled too, it's just that nobody does it.

You need to destroy the location before nulling it, because nulling removes the reference to the location.

but since u use more time the variable and location is removed by custom scripts its ok if u store different reference afyer last was solved with custom script (RemoveLocation/DestroyForce,DestroyGroup etc)
 
Level 10
Joined
Mar 17, 2012
Messages
579
Hi, I am abit confused, I have been told you need to store data in variables to stop it leaking and causing lag/crashes etc, so for example if you are selecting every unit owned by player of type, you need to store it in a variable. Thats fine, I understand that.

But do I then need to destroy that variable after I've used it to stop it leaking? And if so do I need to do this for all variables types?

If your data changes during the game - you should destroy unit groups/remove locations e.t.c... but if not - just leave it be ^_^
 
Level 33
Joined
Mar 27, 2008
Messages
8,035
@Maker
So, we need to null, even globals ? (like what shadowvs posted)

So this is the solution ? (referring to shadowvs's post)
  • Set Location = (Somewhere)
  • Custom script: call RemoveLocation(udg_Location)
  • Custom script: set udg_Location = null
Is it ?
 
Status
Not open for further replies.
Top