HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

static triggers don't leak

01-04-2008, 04:21 PM#1
cohadar
offtopic:
Collapse JASS:
//===========================================================================
public function InitTrig takes nothing returns nothing
local trigger t = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( t, Condition( function Conditions ) )
    call TriggerAddAction( t, function Actions )
    // set t = null  <<static triggers don't leak>>
endfunction
01-04-2008, 04:24 PM#2
Malf
uhh static triggers?
01-04-2008, 04:27 PM#3
cohadar
Triggers that are never destroyed,
effectively all triggers inside InitTrig functions.
01-04-2008, 07:09 PM#4
emjlr3
why is that?
01-04-2008, 07:56 PM#5
cohadar
How can something leak a handle if the object the handle is pointing to never gets destroyed.

The reason for example that unit handles leak is because they die and get removed from game.

Units that point to heroes never leak.

Groups leak because they are created/destroyed
Timers leaks because they are created destroyed.

BUT if you use stuff that recycles timers (aka CSSafety) you don't have to null timers any more.

That is why I also use NewGroup and ReleaseGroup functions
so I recycle groups and never have to null them.
01-04-2008, 10:12 PM#6
Jazradel
But isn't =null releasing the pointer to the handle?
01-05-2008, 12:52 AM#7
uberfoop
How does recycling mean you don't need to null?

There's still a local variable that gets destroyed at the end of a function and a piece of handle pointer data that doesn't. Just because the object is used again doesn't mean you should have a bunch of pointer data floating around.

Correct me if I'm wrong, but I thought that variables had their pointers as independant data only connected to that variable, and thus you could only remove the pointer by making it null with that variable, and if the variable in question is a local, then when it gets destroyed there's no way to go back and get rid of the data.
01-05-2008, 04:21 AM#8
Vexorian
Quote:
There's still a local variable that gets destroyed at the end of a function and a piece of handle pointer data that doesn't.
The local doesn't take space after its scope goes away. If you destroyed a handle and the game would have reasons to think the handle is still pointed by some variable it would keep a safe ghost , but without handle destruction this is not a problem.
01-05-2008, 09:23 AM#9
cohadar
Quote:
Originally Posted by uberfoop
Correct me if I'm wrong, but I thought that variables had their pointers as independant data only connected to that variable, and thus you could only remove the pointer by making it null with that variable, and if the variable in question is a local, then when it gets destroyed there's no way to go back and get rid of the data.

You are wrong. (as already explained by Vex)

Pointers != Handles
01-05-2008, 03:39 PM#10
Malf
Is TT faster than grim001's TimedEvent system??

Collapse TimedEvent:
library TimedEvent initializer Init

globals
 //***   Configuration   ***
 private integer NumberOfTimers = 100
 //*** End Configuration ***

 private integer array TAGS
 private Callback array CALLBACKS
 private timer array TIMERS
 private integer N = 0
endglobals

function interface Callback takes integer tag returns boolean

private function H2I takes handle h returns integer
    return h
    return 0
endfunction

private function TimedEventExpires takes nothing returns nothing
 local timer t = GetExpiredTimer()
 local integer i = H2I(t)-0x100000
    if not CALLBACKS[i].evaluate(TAGS[i]) then
        call PauseTimer(t)
        set N = N + 1
        set TIMERS[N] = t
    endif
endfunction

function TimedEvent takes real delay, integer tag, Callback callback returns nothing
 local timer t
 local integer i
    if N == 0 then
        call BJDebugMsg("TimedEvent Error: Maximum numbers of timers ("+I2S(NumberOfTimers)+") exceeded")
        return
    else
        set t = TIMERS[N]
        set N = N-1
    endif
    set i = H2I(t)-0x100000
    set TAGS[i] = tag
    set CALLBACKS[i] = callback
    call TimerStart(t, delay, true, function TimedEventExpires)
endfunction

private function Init takes nothing returns nothing
 loop
     set TIMERS[N] = CreateTimer()
     exitwhen N == NumberOfTimers-1
     set N = N + 1
 endloop
endfunction

endlibrary
01-05-2008, 03:56 PM#11
Rising_Dusk
Who cares? :/
01-05-2008, 04:13 PM#12
moyack
Because this thread is becoming offtopic, but the topic could be useful for clarification, I moved those post to a proper place.
01-05-2008, 04:33 PM#13
Captain Griffen
Permament handles do not need to have local variables pointing to them nulled.

End of thread.
01-05-2008, 04:51 PM#15
Malf
I have one thing to say to you..

/facepalm


You obviously don't know what you're talking about. The pros have already said it doesn't leak.

Before you respond, go search and find out what "leaks" are and what is "leaking" variables.

I'm off to bed.