HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Does not intitiating a variable use memory?

08-12-2009, 03:27 PM#1
thehellman
For example

local timer t

If I put that at the top, is it using a handle or anything? Should I set t = null at end or something?
08-12-2009, 03:31 PM#2
chobibo
Just set it to null at the end of the function to be safe.
08-12-2009, 03:50 PM#3
Tyrande_ma3x
It isn't using anything since there's basically nothing to point to.
08-12-2009, 04:12 PM#4
Earth-Fury
All variables in Warcraft 3 use 4 bytes of memory. Declaring a variable will reserve that memory. For globals, it will be reserved at map start. Locals are probably stack-allocated, but I don't know about all the complexities of the JASS VM. Agent-type handles are pointers. (as well as a few other handle types, but not all handle types.) The object an agent-type handle points to is separate from the variable containing the 4-byte pointer.

You null reference-counted handle-types (basically, agent-types) because the VM is bugged and will not reduce the reference counts of things held in local variables when a function returns. You only need to null local variables which contain agent-type handles, and you only need to do it before a function returns. (Setting them to any other value reduces the reference count of the agent, and increases the reference count of the new value.)