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

[JASS] Does this leak?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Hi guys, does the following code leak?
JASS:
function Trig_hInitializingActions takes nothing returns nothing
    local group g
    set g = CreatingSomeGroup
    call ForGroup(g, function callback)
    set g = CreatingSomeOtherGroup
    call ForGroup(g, function callback)
    call DestroyGroup(g)
    set g = null
endfunction

Or should I do this?
JASS:
function Trig_hInitializingActions takes nothing returns nothing
    local group g1 = CreatingSomeGroup
    local group g2 = CreatingSomeOtherGroup
    call ForGroup(g1, function callback)
    call DestroyGroup(g1)
    call ForGroup(g2, function callback)
    call DestroyGroup(g2)
    set g1 = null
    set g2 = null
endfunction
 
Last edited:
If you don't use function CreateGroup() in your function you can't say if you leak or not, because then obviosuly SomeGroup and SomeOtherGroup are globals.
And we can't see what else you would do with your globals.

But if you create groups in your function, then your 1st example would leak.

Anyway you would not need two local groups, you also could do:
JASS:
function Trig_hInitializingActions takes nothing returns nothing
    local group myGroup = SomeGroup

    call ForGroup(myGroup, function callback)
    call DestroyGroup(myGroup)

    set myGroup = SomeOtherGroup
    call ForGroup(myGroup, function callback)
    call DestroyGroup(myGroup)

    set myGroup = null
endfunction
 
Status
Not open for further replies.
Top