• 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.
  • 💡 We're thrilled to announce that our upcoming texturing contest is in the works, and we're eager to hear your suggestions! Please take this opportunity to share your ideas in this theme discussion thread for the Texturing Contest #34!
  • 🏆 Hive's 7th HD Modeling Contest: Icecrown Creature is now open! The frozen wastes of Icecrown are home to some of Azeroth’s most terrifying and resilient creatures. For this contest, your challenge is to design and model a HD 3D monster that embodies the cold, undead, and sinister essence of Icecrown! 📅 Submissions close on April 13, 2025. Don't miss this opportunity to let your creativity shine! Enter now and show us your frozen masterpiece! 🔗 Click here to enter!

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

Status
Not open for further replies.
Level 20
Joined
Mar 16, 2008
Messages
868
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 44
Joined
Feb 27, 2007
Messages
5,567
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 14
Joined
Jun 9, 2008
Messages
299
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 72
Joined
Aug 10, 2018
Messages
7,758
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