• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[JASS] Does these few lines leak?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
JASS:
function test takes nothing returns nothing
    ......
    call PauseTimer(LoadTimerHandle(hash,0,0))
    call DestroyTimer(LoadTimerHandle(hash,0,0))
    .......
endfunction

// Does the above code leak? or do I have to do the following?


function test takes nothing returns nothing
    local timer t = LoadTimerHandle(hash,0,0)
    ......
    call PauseTimer(t)
    call DestroyTimer(t)
    .......
    set t = null
endfunction
 
It would not leak, but is less efficient. LoadTimerHandle is a slow operation, and always try to reduce function calls with using variables. (if you would use it more than 1time)

Edit: Ah, and if that timer won't be used again, you have to null it anyway.

Thanks for the reply. The Timer will not be used again, so it should be nulled otherwise it would leak, right?
 
you should actually do the second method, opposing my signature, but LoadTimerHandle is quite costly function, depending on size of the hashtable, and you call it twice, and as Deathismyfriend would say, if you use the same object more than once, cache it into variable

Thanks edo.

Also as edo has said LoadTimerHandle is costly. You should instead save the timers handle id as an integer and load it as an integer. It is much faster especially with a big hashtable.

Also timers always have to be nulled at end of function.
If you do not need the timer anymore then it should be deleted / destroyed then nulled.
 
you should actually do the second method, opposing my signature, but LoadTimerHandle is quite costly function, depending on size of the hashtable, and you call it twice, and as Deathismyfriend would say, if you use the same object more than once, cache it into variable

Thanks edo.

Also as edo has said LoadTimerHandle is costly. You should instead save the timers handle id as an integer and load it as an integer. It is much faster especially with a big hashtable.

Also timers always have to be nulled at end of function.
If you do not need the timer anymore then it should be deleted / destroyed then nulled.

Thanks both of you guys, add rep.
 
You may have to remove the timer handle from the hashtable to get the reference counter down to 0 so the handle ID can be recycled.

Use RemoveSavedHandle.
I'm really not sure about this though. Someone is going to have to test this.

You need to remove the handle from the hashtable for the handle index to be re-used. The reference count for the handle will never reach zero otherwise. It's good programming practice to make a habit of this, since this can limit the number of handle indexes available fast depending on what you do.
 
You may have to remove the timer handle from the hashtable to get the reference counter down to 0 so the handle ID can be recycled.

Use RemoveSavedHandle.
I'm really not sure about this though. Someone is going to have to test this.

You need to remove the handle from the hashtable for the handle index to be re-used. The reference count for the handle will never reach zero otherwise. It's good programming practice to make a habit of this, since this can limit the number of handle indexes available fast depending on what you do.

Thanks for this information. So just flushing the child hashtable is not enough?
 
Status
Not open for further replies.
Back
Top