• 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.

DestroyTimer not working

Status
Not open for further replies.
Level 10
Joined
Mar 26, 2017
Messages
376
After using the DestroyTimer function it appears the timer object is still in memory.
Is it confirmed that this function is broken, and there is no way to prevent timer leak?

If so, could this cause lag/crash a map that creates a huge amount of timers?
 
Level 10
Joined
Mar 26, 2017
Messages
376
Now that I look at it again, I'm not too sure anymore.

What I observe is that when I run:
Code:
t = CreateTimer()
DestroyTimer(t)
print(t) >> mentions there is a timer object in memory
However, I see that this also happens for other types:
Code:
i = CreateItem(1634099555,0,0)
RemoveItem(i)
print(i) >> also mentions there is an item object in memory
Code:
u = CreateUnit(Player(0),1751543663,0,0,0)
RemoveUnit(u)
print(u) >> unit object still in memory


I wouldn't expect the print call to mention there is an object in memory if it has been destroyed.
But observing this response for all object types, it is not really a sign that timers in particular give substantial leak.
 
Last edited:
Level 21
Joined
May 16, 2012
Messages
644
You are printing a handle. An object has a handle that refereces it, so the object is destroyed when you call those functions but you still have a place in memory containing the handle of that object, so you should nullify the variable. Also for timers, if you are using it with hashtables, you should pause the timer before destroying it. If you want to know more about it , read this: JASS Manual: Types
 
Level 10
Joined
Mar 26, 2017
Messages
376
Ah yes, I should have known that it is not possible for a lua function like print to access an object in the game engine.

Chopinski is correct, just remember that you only need to null local variables in JASS (lua no need). Globals never leak references.

Do I understand correctly that a handle which had its object destroyed will be cleaned up at some point (perhaps periodically, or when a certain number of new handles are created).

Do such handles even get cleaned up if they still have a reference to them from a lua variable?
 
Level 21
Joined
May 16, 2012
Messages
644
Do I understand correctly that a handle which had its object destroyed will be cleaned up at some point (perhaps periodically, or when a certain number of new handles are created).

Do such handles even get cleaned up if they still have a reference to them from a lua variable?


JASS sucks when it comes to memory clean up, so you should always assume that you need to do all the dirty work. As Wrda said, when coding in JASS, you should always nullify local variables, as for lua its not needed. In short, if at some point you make a local varible receive an abject, like an effect or a unit you need to make sure that at some point after destroying that object the variable that was pointing to it is nullified.
 
Level 10
Joined
Mar 26, 2017
Messages
376
JASS sucks when it comes to memory clean up, so you should always assume that you need to do all the dirty work. As Wrda said, when coding in JASS, you should always nullify local variables, as for lua its not needed. In short, if at some point you make a local varible receive an abject, like an effect or a unit you need to make sure that at some point after destroying that object the variable that was pointing to it is nullified.

Well, I don't nullify variables in my map, but I use lua :p

If a handle still has reference, I would actually expect the lua garbage collection to spare these handles, and keep them in memory.
 
Status
Not open for further replies.
Top