|This page contains an entry from the official DM Reference.|
At runtime, data objects are garbage collected. That means data which is no longer in use gets automatically deleted to free up system memory. This applies to text strings, lists, savefiles, datum objects, and so on.
What it doesEdit
The garbage collector works by using an efficient reference counting system. Once an item is no longer referenced by any variable, it gets deleted. For the most part, that frees you from having to think about memory allocation, which is wonderful, especially in the case of text strings, which tend to be allocated on the fly all over the place.
Things to knowEdit
There are a couple provisos that you should note. One is that circular
references will never be deleted by the garbage collector. By circular
reference, I mean a pair of objects with variables that point to each
other, or even an object with a variable that points to itself. In rare
cases, you may even depend on this behavior. When you are done with such
objects, you should either null out the circular reference, or you should
forcibly destroy each object with the
Referenced by srcEdit
An object with running or sleeping procs is referenced by the
src variable of those procs and will therefore not be thrown out.
Another note is that the
world.contents list does not count as
a reference. Otherwise, /mob and /obj objects would never be deleted, which
is not the case. Note that objects which are contained by another object or
which contain objects themselves are referenced and will not be
deleted. That means an object must be at
loc=null with no
contents and, of course, no other references anywhere in order to get deleted
by the garbage collector.
Mobs with a non-empty key and all objects with non-empty tags are also immortal.
Turfs and areasEdit
Turfs and areas do not currently get garbage collected.
World shut downEdit
When the world shuts down, all objects are destroyed, whether they are referenced or not. You don't have to worry about system memory getting consumed by persistent objects. That doesn't happen.
The del instructionEdit
In general, people who do not like reference counting garbage collection
should be happy that DM provides a
del instruction, allowing you
to take charge and delete things whether they are referenced or not. Another
nicety is that this automatically nulls out any existing references to the
object, so you don't end up with dangling references to a deleted object,
which can otherwise be a great source of instability and mysterious bugs.