• 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] 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
 
Level 11
Joined
Oct 11, 2012
Messages
711
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?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
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
 
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.
 
Level 11
Joined
Oct 11, 2012
Messages
711
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.
 
Level 5
Joined
Oct 27, 2007
Messages
158
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.
 
Level 11
Joined
Oct 11, 2012
Messages
711
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.
Top