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

[General] Does "set bj_wantDestroyGroup = true" leak?

Status
Not open for further replies.
Level 12
Joined
May 16, 2020
Messages
660
Hi guys

I have been using Ralle's guide so far for everything related to leaks, especially cleaning groups with
  • set bj_wantDestroyGroup = true
Things That Leak

But then I saw this part in this guide:
Memory Leaks

Things that always leak

There are some leaks that you can't prevent.
  • A unit will always keep a tiny bit of memory, even when removed properly. 0.04 kb and unpreventable. (Link)

  • Terrain deformations leak. Including default abilities like shockwave. (reference leak)

  • Very much BJs (Blizzard JASS functions) which are mostly used in GUI have reference leaks.
    You might always look them up to see how a BJ is defined at blizzard.


... Do BJs (I guess that's for example set bj_wantDestroyGroup = true) truly leak?

If so I'd need to create variables for all my groups I created so far :-(
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,567
bj_wantDestroyGroup is a Boolean global variable, not a function (so it's not a Blizzard JASS function aka BJ). Booleans cannot leak, whether they be global or local variables.

You can see bj_wantDestroyGroup referenced inside of Group functions such as this one:
vJASS:
function IsUnitGroupEmptyBJ takes group g returns boolean
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_isUnitGroupEmptyResult = true
    call ForGroup(g, function IsUnitGroupEmptyBJEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(g)
    endif
    return bj_isUnitGroupEmptyResult
endfunction
This function, IsUnitGroupEmptyBJ, is what's called when you use this Condition in GUI:
  • Conditions
    • (SomeUnitGroup is empty) Equal to True
So the IsUnitGroupEmptyBJ function references bj_wantDestroyGroup, which will either be equal to True or False.

You have the option to manually set bj_wantDestroyGroup to True or False before calling this function to control whether or not the Unit Group is destroyed after it's done being used.
True = Destroy, False = Don't destroy.

You've been taking advantage of this by setting bj_wantDestroyGroup to True before using the Pick every unit function (this function creates a Unit Group as well), which tells the Pick every unit function to destroy the Unit Group that it creates after it's done using it.

You can also see that bj_wantDestroyGroup is set to False inside of the functions that reference it. That's the reason why you need to set it to True each time you want to Destroy a Group, since it will be set back to False afterwards.
 
Last edited:
Status
Not open for further replies.
Top