Skip to content

Coding Destroy() procs

Intigracy edited this page Jun 15, 2016 · 4 revisions

**This is an essential part of coding an object, or fixing up older code. **

Background

In byond there are two ways to delete an object,

  1. soft deletion - an object with no references is 'garbage collected' quickly and efficiently every 4 ticks in the background by Byond
  2. hard deletion - an object is immediately removed from the game by Byond with no reference to it, this essentially causes Byond to loop through the entire game world looking for references to this object to remove them (this is exceedingly slow)

Therefore, we always want to ensure that our object undergoes a soft deletion, by removing all references to it when it gets qdel()-ed, the proc that serves this purpose and gets called by qdel() is Destroy().

How we use it

Destroy() at the basic /atom level functions by moving the location of the object to nullspace so that no turf has a reference to it. However each new child should have a Destroy() proc that:

  • Nulls any new variables of the child that holds a reference to an atom/datum/image (making sure it's not referencing other things)
  • Nulls out any references to the object itself, often by having a variable that points to objects that point to it (making sure nothing else is referencing it)
  • Ensures that the object has nothing in contents when it gets deleted (or if it does, qdel's those contents as well)
  • Calls ..(), the parent proc so that each parent Destroy() proc can take care of its own variables for its type