Tutorial How to use Groups without leaking

Jesus4Lyf

Good Idea™
>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
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
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™
>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
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.
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
>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™
>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.
 

Narks

Vastly intelligent whale-like being from the stars
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
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
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.
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

칼리
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:
    seeing some weird stuff doing some moves to the new Weird News forum please see the bathroom admins
  • The Helper The Helper:
    :) it is weird
  • The Helper The Helper:
    btw it was just lag the weirdness is gone
  • Wizard Wizard:
    I checked!
    +1
  • Blackveiled Blackveiled:
    How is everyone doing?
  • Wizard Wizard:
    Alright!
  • The Helper The Helper:
    Doing well thanks!
  • The Helper The Helper:
    Tom Mai check out the post I just found you made in 2006, from an apparent banned account, I do not remember that happening, the post is in the General Discussion Hall of Fame about record breakers
  • Blackveiled Blackveiled:
    Lmao thats somethin right there.
  • tom_mai78101 tom_mai78101:
    How far back were you looking at?
  • tom_mai78101 tom_mai78101:
    But yes, that was me.
  • The Helper The Helper:
    Do you think I am looking back in the forums for this stuff? LOL, no, I find these posts in the Members Online section or the stats - all these old posts I am bumping and moving around are what people are actually looking at on the website
  • tom_mai78101 tom_mai78101:
    Interesting.
  • The Helper The Helper:
    hey Tom your Burrito news is going viral by TheHelper.net standards LOL
  • The Helper The Helper:
    looks like The Burrito has been shared to facebook lol I am getting the facebook bots in now
  • The Helper The Helper:
    I am going to do one more News Forum like the Weird News but this one is Science News for all the cool science and technology articles in the Archive
  • tom_mai78101 tom_mai78101:
    Hmm, do I need to start posting some of the Science and Technology news to this new section in the future?
  • tom_mai78101 tom_mai78101:
    Or do we need to move the news to their respective sections once the threads are old enough, read to be put into the News Archive?
  • The Helper The Helper:
    The 2nd thing
  • The Helper The Helper:
    I have been moving stuff from the current Headline news like a year old and stuff over when I see it in the logs or members online but mostly I have been moving stuff from the Archives
  • The Helper The Helper:
    It is possible to automate it so that instead of moving to Archive if it has the Science, technology or sci tech tag that it gets archived there instead. I am considering a new Weird News Tag
  • tom_mai78101 tom_mai78101:
    Please do. I'll try to tag the news appropriately when I get the chance.
  • The Helper The Helper:
    The new Discourse forum software we are moving to next does alot with the tags and also hashtags
  • The Helper The Helper:
    OK I found the source of your burrito post stuff it is from Reddit and possibly a facebook post too but definitely reddit

    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