Tutorial How to use Groups without leaking

Jesus4Lyf

Good Idea™
Reaction score
397
>This is especially useful as GroupEnum will cause a group to leak even if it is destroyed, so simply using one global group will create only one leak (am I correct in that the leak is only one per group, Jesus4Lyf?).

Yeah. Once a group has an enum called for it, destroying it will leak (as per this tut). It seems that each enum overwrites the data from the previous one that would otherwise leak, or something. :)

I didn't look too deeply as to whether the size of the leak is difference based on how many enums you called, I found the point simply to be that you should recycle groups...

JASS:
function CopyGroup takes group g returns group //This function was NOT written by me, I've got it from a tutorial on wc3c.net
    set bj_groupAddGroupDest = CreateGroup()
    call ForGroup(g, function GroupAddGroupEnum)
    return bj_groupAddGroupDest
endfunction

function CountLivingHeroesOfForce takes force team returns integer
    local integer count = 0
    local unit u
    local group g
    set g = CopyGroup(Heroes)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null 
        if IsPlayerInForce(GetOwningPlayer(u), team) and GetWidgetLife(u) > 0.045 then
            set count = count + 1
        endif
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(g)
    return count
endfunction

-->
JASS:
scope CountLivingHeroesOfForceScope
    globals
        private integer Count
        private force Team
        private unit Enum
    endglobals
    private function CountLivingHeroesOfForceEnum takes nothing returns nothing
        set Enum=GetEnumUnit() // Could be a local, but you'd need to null it then.
        if IsPlayerInForce(GetOwningPlayer(Enum),Team) and GetWidgetLife(Enum)>.405 then // You'd put 0.045.
            set Count=Count+1
        endif
    endfunction
    function CountLivingHeroesOfForce takes force team returns integer
        set Count=0
        set Team=team
        call ForGroup(Heroes,function CountLivingHeroesOfForceEnum)
        return Count
    endfunction
endscope

(I have not syntax checked it.)

>Could somebody explain to me why looping trough a group with FirstOfGroup(group) is deprecated?
It is deprecated in different circumstances for different reasons. In this situation, it is deprecated due to efficiency. The tutorial explains that in other situations, ghost references can cause a FirstOfGroup loop to terminate early (if the group was not created immediately before the FoG loop occurred).

>It should just be as simple as stating that if Create/Destroy group functions are used, that the normal handle nulling rules still apply.
Hm, I'll add that at some point I guess.
 

Deaod

Member
Reaction score
6
Just to stir things a bit up: Safety shouldnt be debug only. Imagine you miss a (critical) bug while testing. Imagine the bugged version would be released. Imagine the bug occurs once every ten games and kills the whole game (for whatever reason).

Also, this was long known and one of the prime reasons why something like GroupUtils exists.
Reinventing the wheel isnt exactly hard, is it?
The size of the leak is not related to the number of times you call an Enum. Either the group or the unit has to change. Else, recycling would be pretty senseless, wouldnt it?
Also note that this bug has nothing to do with handle ids. Different units with the same handle id leak. The same applies to groups.
 

Prozix

New Member
Reaction score
7
Thanks for pointing those things out for me Darthfett and Jesus4lyf.
Captain griffin said:
GroupRefresh does not affect the group in a noticeable way, aside from removing the shadow references in the hash table, which speeds up most operations (see the link above for further details). The only effect it will have on outputs is on FirstOfGroup, which can return null when it comes to a shadow reference in the list, even if there are real units after it. GroupRefresh clears those out, so makes FirstOfGroup act properly again.
I found this in the GroupUtils thread on Wc3C and that's another reason why you should avoid using FirstOfGroup, it can produce unexpected results if your loop ends before it should. Giving 3/12 of the heroes in the game a huge stat bonus would be somewhat unfair I guess.
 

Jesus4Lyf

Good Idea™
Reaction score
397
>Giving 3/12 of the heroes in the game a huge stat bonus would be somewhat unfair I guess.
And if you read this tutorial, you'd know why that's not possible (unless you have temporary heroes in the game).

>Just to stir things a bit up: Safety shouldnt be debug only.
Wrong thread, that's for Recycle. :( Off topic.

>The size of the leak is not related to the number of times you call an Enum. Either the group or the unit has to change.
>Also note that this bug has nothing to do with handle ids. Different units with the same handle id leak. The same applies to groups.

Good information, but I'd have to test it before I include it. It is probably too detailed for this tutorial - unlses you are saying that using different units in enums actually does cause a leak, regardless (because even though the GROUP is not changing, the unit being enummed is - seems to be what you've said).

Then what? Deprecate enums?
 

Deaod

Member
Reaction score
6
unlses you are saying that using different units in enums actually does cause a leak, regardless
Thats what my tests indicated.


Then what? Deprecate enums?
No, those are leaks you cant prevent from happening. You can minimize the leaking through recycling, but even then you still leak a bit. It should be no big deal.
 

Viikuna

No Marlo no game.
Reaction score
265
One more reason for people to do all their group enums with only one group. ( other than that it is the easiest way anyways... )

edit. and maybe you should also recycle all your units, lols.
 

Prozix

New Member
Reaction score
7
>And if you read this tutorial, you'd know why that's not possible (unless you have temporary heroes in the game).
A game where you delete the heroes if a user has left could cause that problem right?
 

Jesus4Lyf

Good Idea™
Reaction score
397
>No, those are leaks you cant prevent from happening.
That's not true. You could use an AIDS struct to form a linked list of every unit in the game, and use that for enumerations. Could be faster than the native enums, you know.

>edit. and maybe you should also recycle all your units, lols.
Or this.

>A game where you delete the heroes if a user has left could cause that problem right?
Yes.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
1.24c on Westfall said:
- Fixed a minor memory leak when using GroupEnum natives.
Is this the create-enum-destroy leak?
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
WTF?!
ARE BLIZZARD FIXING THINGS?!!

Code:
--------------------------------------------------------------------------
Patch 1.24c
--------------------------------------------------------------------------

BUG FIXES
- Fixed a Bug that disabled Spirit Walkers from resurrecting other Spirit 
  Walkers.
- JASS has been disabled.

MAPS

- (6)WizardsRetreat
   - separated two creep camps near both corner starting locations to
     prevent them from calling each other for help when one is attacked.  

- (6)Gnollwood
   - separated two creep camps near merchant buildings to prevent them from 
     calling each other for help when one is attacked.  

- (6)BlizzardTD 
   - Fixed phase-shifting units to behave normally when attacked. 
 
- (12)WormWar 
   - Fixed a bug that causes player worms to become immobile after using
     powerups while respawning.
 

SanKakU

Member
Reaction score
21
i tried changing DoThings but it's not working. i get some bugged error message about my start location (is jasshelper ever going to fix that?)

are you not able to do those things that i'm trying to do?

edit: ah nevermind i have no idea if the problem is with the dothings function...what i want to do is basically something like when a sorceress dies, all the sorceress' owner's scout towers, ziggurats, and watchtowers are destroyed. something like that. what's the best way to do it?


private function DoThings takes nothing returns boolean
if GetUnitTypeId(GetFilterUnit()) == 'opgf' then
call RemoveUnit(GetFilterUnit())
elseif GetUnitTypeId(GetFilterUnit()) == 'ofor' then
call RemoveUnit(GetFilterUnit())
elseif GetUnitTypeId(GetFilterUnit()) 'uzg2' then
call RemoveUnit(GetFilterUnit())
elseif GetUnitTypeId(GetFilterUnit()) 'uzig' then
call RemoveUnit(GetFilterUnit())
elseif GetUnitTypeId(GetFilterUnit()) 'hatw' then
call RemoveUnit(GetFilterUnit())
elseif GetUnitTypeId(GetFilterUnit()) 'hwtw' then
call RemoveUnit(GetFilterUnit())
endif
return false
endfunction
 

mapguy

New Member
Reaction score
46
TO prevent leaks, instead of creating my groups can I do this:

cause dummygroupunit to damage area with 0 damage in 300 radius

Code:
a unit takes damage

damage source equal to my dummygroupunit

add triggering unit to Group_g
//do stuff//
clear all units from group_g
 

Komaqtion

You can change this now in User CP.
Reaction score
469
No...

That will still use a Group Enumeration, and I've also heard it can cause massive problems to Mac users if you use that :S
 

Ayanami

칼리
Reaction score
288
TO prevent leaks, instead of creating my groups can I do this:



Code:
a unit takes damage

damage source equal to my dummygroupunit

add triggering unit to Group_g
//do stuff//
clear all units from group_g

What you can do is use Nestharus's Recycle, which is posted in the first post. Though, you'll have to give up your dreams of "Code everything in GUI", because I gave up that dream long time ago too.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!
  • The Helper The Helper:
    Happy Wednesday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top