proc
ThrowWeapon(mob/thrower,obj/weapon)
var/obj/Projectiles/Weapons/W = new weapon.projectile_type
//obj's New() proc is not modified - no other variables set AFAICT
W.Owner = thrower //Side note: is setting a mob as a var for an object OK to do?
W.loc = thrower.loc
W.step_x = thrower.step_x
W.step_y = thrower.step_y
W.dir = thrower.dir
//In this example, there are no walk() or other movement procs being used (yet)
spawn(10)
GarbageCollect_ThrownWeapon(W)
GarbageCollect_ThrownWeapon(obj/o)
o.Owner = null
o.loc = null
o.step_x = null //do I even need to set these to null?
o.step_y = null // "
o.dir = null // "
spawn(500) //Tried delaying the test, don't know how often collection happens...
GarbageCollectionTest()
//could I have this as: GarbageCollection(o)?
//and skip the for() loop below?
GarbageCollectionTest()
for(var/obj/Projectiles/o in world)
if(o)
debug("Not collected")
else
debug("Collected")//EDIT: Just realised I am a dingus, this line will never be called!
Problem description:
So I've resolved to have proper garbage collection in my project, rather than relying on del. I know there're some threads on it, and Ter13 talks about it a lot, but the info was a little advanced for where I am right now, and I couldn't work out how to apply it yet -sorry!
As far as I can tell, there are no variables left un-nulled, but the collection test proc returns positive.
Is there something I can do to output what vars are yet to be nulled?
How often does garbage collection occur?
Is this a good way of testing for garbage collection?
Would walk(obj,dir) impede garbage collection (not used in the above code yet, but it will be)?
Do I really need to nullify dir and step_x/y?
Answers to the above and anything else relevant would be so appreciated!
Cheers
Edit: I just noticed that, on subsequent uses, "Not Collected" only outputs once each time - suggesting that maybe it has been garbage collected??
I get the same results (one output per call) if I don't nullify "Owner", but get exponential calls if I don't nullify loc.
Not sure what to make of this / why it doesn't just output "Collected"...
For example, if you have this code:
Answer: we can't, so it's garbage collected. Its existence is meaningless/wasted memory because we couldn't use it even if we wanted to, after losing all references to it.