• 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.

[JASS] Help With Leaks

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2007
Messages
1,030
JASS:
function NextPreplaceActions takes nothing returns nothing
local integer a = GetPlayerId(GetTriggerPlayer())
local integer b = IAbsBJ(a-1)
local group g = udg_Units[a]
local group g2 = udg_Units[b]
local integer p = CountUnitsInGroup(g)
local integer k = 1
local unit v

    loop
        exitwhen k>p
        set v = FirstOfGroup(g)
        call UnitRemoveAbility(v,'A000')
        call GroupRemoveUnit(g,v)
        set k = k+1
    endloop
    
    set p = CountUnitsInGroup(g2)
    set k = 1

    loop
        exitwhen k>p
        set v = FirstOfGroup(g2)
        call UnitAddAbility(v,'A000')
        call GroupRemoveUnit(g2,v)
        set k = k+1
    endloop

call DestroyGroup(g)
call DestroyGroup(g2)
set g = null
set v = null
endfunction

My question is concerning the groups. Should I use 1 variable, then destroy it at the end of the function, or should I use 1 variable, and destroy it after the 1st loop and set it to a different group and destroy it again after the second loop, or should I use 2 variables like I am currently doing right now?

A) - 1 Group that I destroy at end
B) - 1 Group that I destroy every time I change it
C) - 2 Groups that I destroy at the end
 
Level 4
Joined
Jul 24, 2008
Messages
108
I'm not very good at JASS, but from the feedback i've been getting from others around this side, I do not see any sources of leaks that are obvious, tho looking at this line right here
JASS:
local integer b = IAbsBJ(a-1)

Don't BJs usually leak? Just a hunch, I am no where near pro at this yet :) But other than that i see nothing obvious that a notice like me would see
 
Level 4
Joined
Aug 9, 2004
Messages
70
Here is what I think.

When you write, local group g, you are typically ordering your computer that "hey, I'm gonna need some space, so get it to me. And it's getting some free space but nothing inside yet. Let's say it's like 4kb for a group. (Just an example.) But that 4kb is not full yet. It's just empty.

if you say set g = udg_Units[], now you started to fill that empty space with data.
and if you call DestroyGroup func, this means release the data.
and the last, by calling set g = null you are ordering your computer to free that space, you don't need it anymore.

So what I'm suggesting is (because that I'm not really sure) try the both way and see the results. First try one group, destroy it in the middle and before nullifying use it for the second loop, then destroy it again and nullify. Second try, nullify in the middle and before destroying it, use it for the second loop, then destroy and nullify.

One or another should be working. I'd say the first one is ok, but not sure...
 
Ok this avoids all leaks and only uses 1 group:
JASS:
function NextPreplaceActions takes nothing returns nothing
  local integer a = GetPlayerId(GetTriggerPlayer())
  local integer b = IAbsBJ(a-1)
  local group g = udg_Units[a]
  local integer p = CountUnitsInGroup(g)
  local integer k = 1
  local unit v

    loop
        exitwhen k>p
        set v = FirstOfGroup(g)
        call UnitRemoveAbility(v,'A000')
        call GroupRemoveUnit(g,v)
        set k = k+1
    endloop
    
    call DestroyGroup(g)
    set g = null
    set g = udg_Units[b]

    set p = CountUnitsInGroup(g)
    set k = 1

    loop
        exitwhen k>p
        set v = FirstOfGroup(g)
        call UnitAddAbility(v,'A000')
        call GroupRemoveUnit(g,v)
        set k = k+1
    endloop

    call DestroyGroup(g)
  set g = null
  set v = null
endfunction

EDIT: btw BJs that deal with integers do not leak. Only a few which deal with handles.

EDIT 2: and CountUnitsInGroup is one of the few useful functions which aren't native which blizzard made.
 
Status
Not open for further replies.
Top