• 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.

[Solved] Pick all unit of type : how to work around it to avoid leaks ?

Status
Not open for further replies.
Level 6
Joined
Jan 12, 2014
Messages
59
Hello,

I'm trying to reduce as much as i can the leaks on my map, but i can't find a way to NOT use "pick all units of type" in certain situations. And, as i saw, this action leaks whatever you do.
Is there a way to work around that ?
I don't do JASS, so if you do, explain to me like i'm five.
Maybe there is some shenanigans to achieve the same goal by a different way, but i don't know it.

thank you !
 
Level 14
Joined
Jan 24, 2017
Messages
280

Check the first leak. The pick all units of type creates a unit group that leaks. You can destory it using a custom script before:
JASS:
set bj_wantDestroyGroup = true
Or you can set it to a variable and then delete the unit group afterwards.
 
Last edited:
Level 6
Joined
Jan 12, 2014
Messages
59

Check the first leak. The pick all units of type creates a unit group that leaks. You can destory it using a custom script before:
JASS:
set bj_wantDestroyGroup = true
Or you can set it to a variable and then delete the unit group afterwards.
I don't understand the "set bj_wantDestroyGroup = true" > what is his effect ?

Does it mean that i can do something like :
- Pick all units of type and add it to "UnitGrp"
- Take all units in "UnitGrp" and do actions
actions
- custom script: call DestroyGroup(udg_UnitGrp)

?

But as i use Pick every unit of type, i should leak anyways , right ?
Even in the post you sent there is a part : "Never use these functions"
 
Level 14
Joined
Jan 24, 2017
Messages
280
Does it mean that i can do something like :
- Pick all units of type and add it to "UnitGrp"
- Take all units in "UnitGrp" and do actions
actions
- custom script: call DestroyGroup(udg_UnitGrp)

?

But as i use Pick every unit of type, i should leak anyways , right ?
Even in the post you sent there is a part : "Never use these functions"
Not exactly. You want to set it to a variable when you call: All units of type.
 
Level 6
Joined
Jan 12, 2014
Messages
59
Explain with more details please, i do not understand.

what "set bj_wantDestroyGroup = true" does ?

You want to set it to a variable when you call: All units of type.
I want to set what to a variable?
Let's say i have a UnitGroup variable called "UnitGroup"
What do i do then ?
Why can't i do :
- Pick all units of type and add it to "UnitGroup"
Then destroy the group ?
 
Level 14
Joined
Jan 24, 2017
Messages
280
  • set.gif
    Set GroupVar = Pick every unit in (Playable Map Area)
  • unitgroup.gif
    Unit Group - Pick every unit in GroupVar and do (Unit - Hide (Picked unit))
  • page.gif
    Custom script: call DestroyGroup(udg_GroupVar)
 
Level 29
Joined
Sep 26, 2009
Messages
2,596
A small note from me on why the following always leaks and should not be used:
  • Set VariableSet group = (Units of type Footman)
If you translate this GUI action into jass, you will see this:
JASS:
set udg_group = GetUnitsOfTypeIdAll('hfoo')
If you look up GetUnitsOfTypeIdAll function for example here Doc - GetUnitsOfTypeIdAll, you will see the function's implementation and explanation why it leaks:
Leaks handle result: In Jass you must set local variables that hold agents (or any child type) to null at the end of functions to avoid reference counter leaks.
Leaks handle g: In Jass you must set local variables that hold agents (or any child type) to null at the end of functions to avoid reference counter leaks.

So if you need to pick all units of certain unit-type, you should use something like this instead:
  • Set VariableSet group = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Footman))
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
And what is "set bj_wantDestroyGroup = true" ?
It's a bonus feature built into many of the blizzard group-related functions. Many of them check this boolean variable, and if it's true they will automatically destroy the group at the end of their execution. Effectively it allows you to tell the function to clean up after itself, but not all group functions check it and the first such function to encounter the variable will set it back to false and then destroy its group.
 
Level 6
Joined
Jan 12, 2014
Messages
59
It's a bonus feature built into many of the blizzard group-related functions. Many of them check this boolean variable, and if it's true they will automatically destroy the group at the end of their execution. Effectively it allows you to tell the function to clean up after itself, but not all group functions check it and the first such function to encounter the variable will set it back to false and then destroy its group.
thanks for the explainations, but i think i don't understand it enough to use it properly without causing unwanted side effects. Let's stick with the "Set UnitGrpVar" then destroy it with custom scripts
 
Status
Not open for further replies.
Top