Merge pull request #3867 from Citadel-Station-13/upstream-merge-32504

[MIRROR] Weakrefs
This commit is contained in:
LetterJay
2017-11-13 11:41:38 -06:00
committed by GitHub
7 changed files with 41 additions and 16 deletions
+2
View File
@@ -4,6 +4,7 @@
var/list/datum_components //for /datum/components
var/ui_screen = "home" //for tgui
var/use_tag = FALSE
var/datum/weakref/weak_reference
#ifdef TESTING
var/running_find_references
@@ -15,6 +16,7 @@
// Return the appropriate QDEL_HINT; in most cases this is QDEL_HINT_QUEUE.
/datum/proc/Destroy(force=FALSE, ...)
tag = null
weak_reference = null //ensure prompt GCing of weakref.
var/list/timers = active_timers
active_timers = null
for(var/thing in timers)
+19
View File
@@ -0,0 +1,19 @@
/proc/WEAKREF(datum/input)
if(istype(input) && !QDELETED(input))
if(!input.weak_reference)
input.weak_reference = new /datum/weakref(input)
return input.weak_reference
/datum/weakref
var/reference
/datum/weakref/New(datum/thing)
reference = REF(thing)
/datum/weakref/Destroy()
return QDEL_HINT_LETMELIVE //Let BYOND autoGC thiswhen nothing is using it anymore.
/datum/weakref/proc/resolve()
var/datum/D = locate(reference)
return D.weak_reference == src? D : null