• 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] Filters leak?

Status
Not open for further replies.
Level 11
Joined
Apr 6, 2008
Messages
760
im petty sure it do but ill ask just to be sure

do this leak?

JASS:
function MPick_Conds takes nothing returns boolean
    local timer Mtimer
    local unit c
    set Mtimer = GetExpiredTimer()
    set c = GetHandleUnit(Mtimer,"c")
    return GetWidgetLife(GetFilterUnit()) > .405 and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(c))
endfunction

and the "caller"

JASS:
call GroupEnumUnitsInRange(g,nx,ny,300,Filter(function MPick_Conds))

its a bitch since a cant
JASS:
set c = null
 
Last edited:
Level 5
Joined
Oct 27, 2007
Messages
158
im petty sure it do but ill ask just to be sure

do this leak?

JASS:
function MPick_Conds takes nothing returns boolean
    local timer Mtimer
    local unit c
    set Mtimer = GetExpiredTimer()
    set c = GetHandleUnit(Mtimer,"c")
    return GetWidgetLife(GetFilterUnit()) > .405 and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(c))
endfunction
and the "caller"

JASS:
call GroupEnumUnitsInRange(g,nx,ny,300,Filter(function MPick_Conds))
its a bitch since a cant
JASS:
set c = null

JASS:
function MPick_Conds takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > .405 and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetHandleUnit(GetExpiredTimer(),"c")))
endfunction

The filter doesn't need to be destroyed if you use it more than once. Everytime you call Filter with the same func, it'll return a handle to the same filter object. If however you use a local filter type handle, then you need to null the filter type handle at the end of the function. It's not logical, but that's because of a stupid programming error, where references are not decremented when a local goes out of scope. The nulling though is only important if you have to destroy the filter at one point where it isn't needed anymore.

The reason this does not leak is because you're passing the arguments by value and not by reference.
 
Level 9
Joined
Mar 25, 2005
Messages
252
Your local timer and unit leak, but there is an easy fix:
JASS:
function MPick_Conds takes nothing returns boolean
    return GetWidgetLife(GetFilterUnit()) > .405 and not IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) and IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(GetHandleUnit(GetExpiredTimer(),"c")))
endfunction
Though I don't know if GetExpiredTimer works in a filter function
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
globals
filterfunc f

function blabla_InitTrig ....
set f = Filter(function halelelujah)

and use f in your triggers
 
Level 19
Joined
Aug 24, 2007
Messages
2,888
Vexorian said null as filter leaks I always use a global due to speed and make sure
but I trust Poot more than Vexorian, his words are truths for me
 
Status
Not open for further replies.
Top