Game Development Community

Memory Management in TorqueScript

by BlueRaja · in Torque Game Builder · 08/08/2008 (8:42 am) · 4 replies

I was under the impression that TorqueScript had automated garbage collection, but it seems that %myObj.delete() is advocated a bit too highly for that to be the case. So my questions are:
1. Is it necessary to use %myObj.delete() for local variables (either normal variables, or ones declared with new)?
2. If there is garbage collection, what happens when a SimSet / SimGroup goes out of scope or is deleted somehow? Can the garbage collector effectively deal with circular references?
3. What's the difference between delete(), deleteObject(), unregisterObject(), and deleteVariable()? When should they be used?

#1
08/08/2008 (11:26 am)
Define what you mean by "garbage collection".

If you are assuming that Torque will release memory back to the operating system, that does not happen.

Neither does Torque delete objects themselves on it's own--objects are never "out of scope", since they can be referenced anywhere by name or ID.

TorqueScript will destroy the stack for any local execution space, so locally defined variables used within a scope block will "go away", but the memory is simply allocated as free for future Torque use, not released back to the OS.
#2
08/08/2008 (11:38 am)
Thank you, that answers my first two questions; what about #3?
#3
08/08/2008 (12:32 pm)
Your default should simply be delete(), as it encompasses all of the normal needs. I'm not aware of any current utilization of deleteObject() or deleteVariable() other than low level code, and unregisterObject() is for very specific use only (and is called by delete() in any case).
#4
08/08/2008 (12:41 pm)
Ah - thank you for taking the time to clarify that, Stephen, it's much appreciated :)