ID:1436842
 
Applies to:Dream Seeker
Status: Open

Issue hasn't been assigned a status value.
When debugging my game, I often keep track of how many instances of each object I have.
Right now, I use the following
(WARNING: Bad code, just slapped it to together to get an instance count.)

/debug_item_track
var/path_type = ""
var/count = 1
New(var/i)
src.path_type = i

mob/Stat()
statpanel("Debug Atom Counts")

var/list/counter = list()
for(var/obj/A)
var/found_one = FALSE
for(var/debug_item_track/D in counter)
if("[D.path_type]" == "[A.type]") {D.count += 1; found_one = TRUE; break}
if(!found_one) {counter.Add(new /debug_item_track("[A.type]"))}
for(var/mob/A)
var/found_one = FALSE
for(var/debug_item_track/D in counter)
if("[D.path_type]" == "[A.type]") {D.count += 1; found_one = TRUE; break}
if(!found_one) {counter.Add(new /debug_item_track("[A.type]"))}

for(var/debug_item_track/t in counter)
stat(t.path_type, t.count)


The only problem with this, is I believe it's stopping the garbage collector from actually working?

I see specific objects that are in the list, when they shouldn't be, as they are just overlays.

See screenshot for example:

I genuinely am not sure if it's my code above that's preventing garbage collection, or if it's an issue with my hud engine not cleaning up after creation.

It's difficult to tell, because if I disable the code above, I'll have no way of knowing if the garbage collector has picked it up or not.

~~~~~~~~~

In the Profile Tab, can we have the ability to see how many instances of each object there currently is in a world?
I would love to see this implemented!
I'm surprised there isn't something similar to this already!

+1! :)
It think this would be great as well. This would make it much easier to track screen object instances as well as not preventing garbage collection.
sure. don't we have something like this anyways, for linux users? it's not as detailed as this, but SIGUSR2 kind of gets this kind of info for the whole world, per lowest level object type/prototype.
Any word on this feature?
If you want to keep track of references without actually referencing the object, just modify a variable (number or text) instead of holding a reference. Also make sure that your object reference reporting proc is called less frequently than world.tick_lag or else you'll never give the garbage collector time to see that an object has no references. I believe you are possibly seeing some issues with your GUI implementation as well.

Some critique; you don't want to be creating a blank list every single time Stat() is called. Instead, keep a global list somewhere and re-use it. I would also try to think of a way to only count new atoms instead of looping through all atoms and mobs every Stat() call. You can do this via a series of lists.
Well, the whole issue with my implementation is that it's not giving the garbage collector time to run, as those objects are pretty much constantly being referenced. I would think a built-in implementation would be much smoother.
Well, with just object type counters and hooks into Del() to decrement, they aren't referenced?