Files
CHOMPStation2/code/datums/weakref.dm
PsiOmegaDelta ebe5cc916d Port of @PsiOmegaDelta's Baystation12/Baystation12#16820
Ports tg's garbage collector subsystem and Destroy() returning qdel hints.
2017-06-05 22:10:06 -04:00

33 lines
711 B
Plaintext

/datum
var/weakref/weakref
/datum/Destroy()
weakref = null // Clear this reference to ensure it's kept for as brief duration as possible.
. = ..()
//obtain a weak reference to a datum
/proc/weakref(datum/D)
if(!istype(D))
return
if(QDELETED(D))
return
if(!D.weakref)
D.weakref = new/weakref(D)
return D.weakref
/weakref
var/ref
/weakref/New(datum/D)
ref = "\ref[D]"
/weakref/Destroy()
// A weakref datum should not be manually destroyed as it is a shared resource,
// rather it should be automatically collected by the BYOND GC when all references are gone.
return QDEL_HINT_LETMELIVE
/weakref/proc/resolve()
var/datum/D = locate(ref)
if(D && D.weakref == src)
return D
return null