• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

unit group handles

Status
Not open for further replies.
Level 4
Joined
Feb 22, 2012
Messages
74
I have a question, does the unit group only leak if you SET a group, not ADD to a group?

I have noticed if I destroy a group, I can later set the group again, i.e.

call DestroyGroup(udg_tempGroup)
...
set tempGroup = all units within...

works.


But cannot add to a group that has not been "set" after being destroyed. Can I get around this by doing:

call DestroyGroup
set tempGroup = null
add unit to tempGroup
 
Setting a tempGroup will create a unit group. Adding units does not. Adding units assumes that the group is already created. (it doesn't create a new group by itself) So in the example you posted, it would be adding units to a destroyed group (basically a nonexistent group), so it won't do anything.

You can use:
  • Custom script: set udg_tempGroup = CreateGroup()
To create a new group, and then you can add units to it. You don't necessarily need to destroy it right away, it really depends on how you are going to use the group. If you know you need to use that specific group later on and you aren't going to lose reference to it (meaning, you won't set the tempGroup variable to something else), then you don't need to destroy it.
 
Well, a memory leak occurs when you lose reference to it.

Take for example a man holding two sticks, one in each hand. He has a box of sticks right next to him. Those sticks represent groups. At the moment, he has access to both of the sticks in his hands. However, if he drops a stick, he will no longer be able to access it. Also, if he grabs a new stick in replacement of the old, the old one will drop and he won't have access to it anymore.

That was a very weird example, yes, but hopefully it will make things clearer. Once you don't have any variables that point to a group anymore, it is just "lost in memory". You can't go back and destroy it because no variable points to it.

So to answer your question:
as long as i dont set the group again before destroying it, it wont leak?

Yep. The reason why we destroy things is:
1) If we are going to change what a variable points to (a.k.a. what it "contains"), we will want to destroy whatever it currently points to so that it won't randomly float in memory.
2) If we no longer need that specific group or location or whatever, then there is no point in it being left in memory, right? Therefore, we can just destroy it and get on with our lives.

do you have to set = null any variable that you destroy for it to not leak?

No, that is for "local" variables which you will most likely not need to pay much mind to unless you use JASS. All the variables you create through the variable editor are "globals" and not subject to the glitch/bug that local variables have.

Let me know if that didn't explain it well enough, or if you are still confused. =)
 
Status
Not open for further replies.
Top