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

Confused if 'pick every unit' loop order creates memory leak

Status
Not open for further replies.
Level 18
Joined
Mar 16, 2008
Messages
721
Reading other forum posts has confused me, they said 'mass orders' create a memory leak.

  • Idle Units
    • Events
  • ...
    • Conditions
    • Actions
      • Unit Group - Pick every unit in MobaUnits_West[1] and do (Actions)
        • Loop - Actions
          • Unit - Order (Picked unit) to Attack-Move To RedMobaSpawnWest
when the units are created they are added to the unit group and changed to different array in that unit group as they reach different points, the units are removed from the group when they die.
 
Level 39
Joined
Feb 27, 2007
Messages
5,013
Just... think about it. Is a group being created that's not being destroyed or cleared? No. Is a point being referenced that is not stored in a variable (to re-use) or immediately removed? No. Then you're not leaking anything. The real problem with Unit Group - Issue Order... is the caveat GUI shows you: "This will issue an order to at most 12 units from the specified unit group."

 
Level 13
Joined
Jun 9, 2008
Messages
258
Yeah but I second this because I too have read conflicting things about this. I believe another masterpost about leaks says "Pick every unit in unit group" is a blacklisted function because there is no way to stop it from leaking

which would be VERY unfortunate because I kinda base my whole current project on periodic 2 seconds "pick every unit in unit group".

I thought it would be enough to use custom script to destroy the unit groups after use, since that was suggested in a couple of posts.

So is the function "blacklisted" or not? If yes, what alternative can one use?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,542
Yeah but I second this because I too have read conflicting things about this. I believe another masterpost about leaks says "Pick every unit in unit group" is a blacklisted function because there is no way to stop it from leaking

which would be VERY unfortunate because I kinda base my whole current project on periodic 2 seconds "pick every unit in unit group".

I thought it would be enough to use custom script to destroy the unit groups after use, since that was suggested in a couple of posts.

So is the function "blacklisted" or not? If yes, what alternative can one use?
Gnuoy's trigger does not have a single memory leak in it as both the Unit Group that's referenced in the Pick Every Unit function:
  • MobaUnits_West[1]
And the Point where the units are being ordered to attack to:
  • RedMobaSpawnWest
Are both being tracked by a variable. This means that you have access to this Unit Group and Point at any given time by referencing these variables. This fact is the exact opposite of a memory leak. A memory leak is when you lose track of something and can no longer reference it, but this only applies to certain types of data (Unit Group, Player Group, Point, Special Effect, etc). Look into that tutorial that Pyrogasm linked to get a better understanding of what I mean.

Regarding the use of the Pick Every Unit function, it is the main way for you to interact with units in a Unit Group in GUI. It's NOT a blacklisted function, however, it can be used to create a Unit Group in a way that IS blacklisted. For example, I've heard that creating a Unit Group using Units of Type will create an unavoidable leak. If that's true then you'd want to avoid that specific method of creating a Unit Group but not the function as a whole. And don't worry, there's alternative solutions.

To better understand this stuff I find that it helps to learn a little bit of Jass as it teaches you exactly what is going on behind the scenes.
Here's how a Unit Group is created for instance. Note how there's an actual function for creating the Unit Group which you don't see in GUI:
vJASS:
local group MyUnitGroup = CreateGroup()
Understanding how Unit Groups and memory leaks work will help you understand why you'd want to get rid of a Unit Group and why you'd want to preserve one. There's a bit more to it than that but that's why tutorials were made.


Anyway, I believe creating your Unit Groups (aka Setting them) using Matching conditions should almost always be safe:
  • Set Variable MyUnitGroup = Units matching X conditions...
Also, remember that some threads on Hive are very old and things have changed over the years. Some information is outdated.
 
Last edited:
Status
Not open for further replies.
Top