• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

A question about leaks for a dummies.

Level 8
Joined
Apr 16, 2025
Messages
160
It's about groups. I know that if you create a global group of units without the "set bj_wantDestroyGroup = true" function before creating the group, you will get a leak.

But what about the own group variable? There's only one of them and it's not going anywhere. At worst, units will accumulate there, but since they're dead, what difference does it make, right? Or does it really hurt performance?

P.S. I know how to clear the unit group variable, I just don't fully understand if it's necessary.
 
The simple answer:
Yes, if you only ever Set the global group ONE TIME then it's NOT a memory leak and you don't have to clean it up.

It will only become a memory leak once you've lost your reference to it. This could happen if you Set the variable keeping track of it to something else.

Regarding the dead units piling up, you can just remove them manually:
  • Events
    • Unit - A unit Dies
  • Conditions
    • // To optimize this, mark your units ahead of time so that you know whether they're in the group or not
  • Actions
    • Unit Group - Remove (Triggering unit) from MyGroup
Plus if you ever Loop over the group you can use an If Then Else to check each (Picked unit)'s living status and remove any dead ones:
  • Actions
    • Unit Group - Pick every unit in MyGroup and do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Picked unit) is Alive) Equal to True
          • Then - Actions
            • -------- They're alive, do stuff --------
          • Else - Actions
            • Unit Group - Remove (Picked unit) from MyGroup
You should be removing these unwanted units from the group!



The advanced answer:
Whenever you Set a Unit Group variable you're actually creating a new Unit Group object. This is a completely unique group. The variable only acts as a reference or pointer to this object.

With that in mind, let's look at this trigger:
  • Actions
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
^ There is no memory leak here. Why? Because you can still destroy MyGroup.

However, a memory leak would occur the moment you do something like this:
  • Actions
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
^ There is 1 memory leak here. The Unit Group that was created when you first Set MyGroup is now lost. You can only Destroy the second Unit Group that is being tracked in the last setting of MyGroup.

  • Actions
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
^ There is 2 memory leaks here. You've lost reference to the first and second Unit Groups. You can still Destroy the third Unit Group.

Now with the Custom Script:
  • Actions
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
    • Set Variable MyGroup = (Units owned by Player 1 (Red))
    • Custom script: call DestroyGroup( udg_MyGroup )
^ The Custom Script is only destroying the very last MyGroup. The first two are ignored. So you've created 3 unique Unit Group objects in this trigger but you've only destroyed the last object. You can't actually destroy the other two objects because you have no way of referencing them from within the DestroyGroup() function. They're officially considered memory leaks and will exist in your computer's memory until you exit the map.
 
Last edited:
Very good detailed answer, thank you very much!

It's funny that it just so happened that I add each unit to the squad via the function "squad = add unit to this squad". I really hope that this does not create leaks, otherwise there will be millions of them)))
No problem, and I'm guessing you mean this?
  • Actions
    • Unit Group - Add (Triggering unit) to YourUnitGroup
Adding a unit to a group doesn't create a new Unit Group object - so no leaks. You're simply adding the unit to an existing one.

But a "unit leak" would occur if the group contains any dead or "removed from game" units. That's why I recommended removing them from the group. Plus there's all sorts of bugs that can occur when you try to interact with these unwanted units. You're assuming that your Actions will handle dead units properly but that's not always a safe assumption.
 
Last edited:
Back
Top