Game Development Community

What's the deal with deleting script objects?

by Justin Tolchin · in Torque Game Engine · 03/28/2005 (12:53 pm) · 4 replies

Hi all,

Just wondering if there's any automatic "garbage collection" or anything in Torque Script? I've seen a few posts that refer to either calling something like %obj.delete() or %obj.deleteObject(), and something about a deleteVariables function, but I can't find any actual Torque documentation on them. Can anyone enlighten me on this? Does Torque do any reference counting and automatically delete objects without references? Or do I always have to delete things explicitly?

I'm also wondering what happens if I have a SimObject containing a SimSet of objects, and those objects themselves contain SimSets of other objects. If I delete one of the objects from the "top-level" SimSet will the contained SimSet objects get deleted? What if I delete the SimObject itself? Do the SimSet elements get nuked or do I have to loop through them and delete them manually?

Thanks!

#1
03/28/2005 (2:24 pm)
SimGroups have auto-delete of contents (that's why an object can only be a member of one SimGroup at a time), while SimSets do not.

This is why you often see the MissionCleanup.add(%objectID); command when objects are created--it's a handy way to ensure cleanup of your script objects when you know that they will be around until the end of the mission, but don't want them any longer after mission ends.
#2
03/29/2005 (9:11 am)
Hi Stephen,

Actually I'm more interested in the objects that *won't* be around until the end of the mission. Specifically I'm implementing kind of a "stack" concept where I push AI "tasks" onto a stack and pop them off when they're complete. The "task" objects also contain an array of "subtasks". When a subtask is finished it gets popped off the subtasks stack, and when the last subtask is complete, the task it belongs to gets popped off the task stack. (BTW, I'm not actually using SimSets for these arrays, I'm using the Array class from a resource that someone posted a while ago, but I figured SimSets would make a decent example.)

I just want to insure that these tasks and subtasks get deleted when they are popped off the stack so I don't leak memory, and I wasn't sure if I had to do this manually (and if so, how to go about it) or if the script engine somehow "knows" when an object is no longer being referenced by any variable and therefore is safe to delete. I get the sense from other posts I've read that I have to do this manually in most cases, but what the actual syntax is I'm still unclear on.
#3
03/29/2005 (9:17 am)
Call %object.delete(); when you want them deleted.
#4
03/30/2005 (1:51 pm)
Thanks, Stephen. As usual I was trying to make this harder than it needed to be. :-)