Add reference collection to garbage collector

This commit is contained in:
Markolie
2015-09-18 05:01:53 +02:00
parent d921f473f1
commit 9ffd7de976
3 changed files with 79 additions and 2 deletions
@@ -136,6 +136,11 @@ var/global/datum/controller/process/garbage_collector/garbageCollector
garbageCollector.dels_count++
if (QDEL_HINT_PUTINPOOL) //qdel will put this object in the pool.
PlaceInPool(D,0)
if (QDEL_HINT_FINDREFERENCE)//qdel will, if TESTING is enabled, display all references to this object, then queue the object for deletion.
#ifdef TESTING
D.find_references(remove_from_queue = FALSE)
#endif
garbageCollector.addTrash(D)
else
// world << "WARNING GC DID NOT GET A RETURN VALUE FOR [D], [D.type]!"
garbageCollector.addTrash(D)
@@ -176,3 +181,72 @@ var/global/datum/controller/process/garbage_collector/garbageCollector
/proc/gcwarning(msg)
log_to_dd("## GC WARNING: [msg]")
#ifdef TESTING
/client/var/running_find_references
/datum/var/running_find_references
/datum/verb/find_references(remove_from_queue = TRUE as num)
set category = "Debug"
set name = "Find References"
set background = 1
set src in world
running_find_references = type
if(usr && usr.client)
if(usr.client.running_find_references)
testing("CANCELLED search for references to a [usr.client.running_find_references].")
usr.client.running_find_references = null
running_find_references = null
return
if(alert("Running this will create a lot of lag until it finishes. You can cancel it by running it again. Would you like to begin the search?", "Find References", "Yes", "No") == "No")
running_find_references = null
return
// Remove this object from the list of things to be auto-deleted.
if(remove_from_queue && garbageCollector && ("\ref[src]" in garbageCollector.queue))
garbageCollector.queue -= "\ref[src]"
if(usr && usr.client)
usr.client.running_find_references = type
testing("Beginning search for references to a [type].")
var/list/things = list()
for(var/client/thing)
things |= thing
for(var/datum/thing)
things |= thing
testing("Collected list of things in search for references to a [type]. ([things.len] Thing\s)")
for(var/datum/thing in things)
if(usr && usr.client && !usr.client.running_find_references) return
for(var/varname in thing.vars)
var/variable = thing.vars[varname]
if(variable == src)
testing("Found [src.type] \ref[src] in [thing.type]'s [varname] var.")
else if(islist(variable))
if(src in variable)
testing("Found [src.type] \ref[src] in [thing.type]'s [varname] list var.")
testing("Completed search for references to a [type].")
if(usr && usr.client)
usr.client.running_find_references = null
running_find_references = null
/client/verb/purge_all_destroyed_objects()
set category = "Debug"
if(garbageCollector)
while(garbageCollector.queue.len)
var/datum/o = locate(garbageCollector.queue[1])
if(istype(o) && o.gcDestroyed)
del(o)
garbageCollector.dels_count++
garbageCollector.queue.Cut(1, 2)
/datum/verb/qdel_then_find_references()
set category = "Debug"
set name = "qdel() then Find References"
set background = 1
set src in world
qdel(src)
if(!running_find_references)
find_references(remove_from_queue = FALSE)
#endif