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.
  • The Helper The Helper:
    that sucks i bet they are expensive
  • Varine Varine:
    Not really
  • Varine Varine:
    The entire hot end is like 20 dollars, I just can't get anymore until next week
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top