BYOND and OpenDream handle garbage collection in fundamentally different ways. Whilst BYOND counts the number of references to an object to determine when it's no longer in use, OpenDream relies on the Common Language Runtime's implementation of a tracing garbage collector to free objects.
The difference in garbage collection between OpenDream and BYOND is important to consider when implementing a garbage collection strategy as an end user.
## Hard Deletions
Hard deletions refer to immediately removing an object from the engine's memory space. This is done via the `del()` proc.
BYOND scans through all objects to remove all references to the object, before finally freeing it. Although there are a few optimizations, this is still an expensive process, especially in games with a large amount of objects.
OpenDream handles this by dropping all data held by an object and turning it into a "zombie object". The object itself will continue to exist, however the release of its data will be deferred to the CLR, and DM will not recognize the object and treat it as `null`. This process is instantaneous, however it creates a sort of "memory leak" of ~64 bytes, because it cannot be interacted with in DM and the "zombie object" won't be garbage collected if it was referenced by other objects before being deleted.
## Soft Deletions
Soft deletions refer to objects being freed through them not being referenced anymore.
BYOND detects these objects via their internal reference count, and frees them when this count is 0. This process is cheap and deterministic, as an object is freed immediately after its refcount reaches 0.
OpenDream relies on the CLR's garbage collector to detect when an object is not referenced. This process should also not impact performance, but crucially it is not deterministic. The garbage collector runs parallel to the main engine thread, is invisible to OpenDream and determines when it needs to collect via an involved algorithm.
## refcount() in OpenDream
Reference counting in OpenDream is not supported, since there is no good way of tracking references out of the box, and implementing reference counting is not a planned feature. Developers should consider using `del()` instead of relying on soft deletions.