In response to Stephen001
Which is what?
Well, ordinarily, if your code is in such a situation where you can add object references, but have no sensible context with which to remove them again from the thing you added them to, you probably have spaghetti code, and very odd divisions of responsibility within the codebase.

Usually whatever passes a reference into an object, should be able to fetch/use that object again to remove said reference later.
Usually whatever passes a reference into an object, should be able to fetch/use that object again to remove said reference later.

Moreover, you need to break circular references and only maintain references when they are needed.

Eric.partymembers = list(Tom, Jeff, Tim)
Tom.partymembers = list(Eric, Jeff, Tim)
Jeff.partymembers = list(Eric, Tom, Tim)
Tim.partymembers = list(Eric, Tom, Jeff)


In the above example, none of the above objects can be deleted until all of them are deleted, or you explicitly delete one.

So, in order to ensure that we aren't keeping our friends around when we don't need to, we can do something like the below:

mob
Logout()
for(var/mob/m in src.partymembers)
m.leftParty(src)
src.partymembers = null
. = ..()
proc
leftParty(guy)
src.partymembers -= guy


Even better, we could abstract this behavior, and only keep a singular reference to the entire party:

party
var
list/members = list()
proc
leftParty(guy)
src.members -= guy

mob
party/party
Logout()
src.party.leftParty(src)
src.party = null
. = ..()


In this scenario, until the circular references are cleaned up, neither the party members, nor the party itself can be removed by the garbage collector.

Usually, it's better to recycle objects rather than letting the garbage collector have them, but it's just better to design your systems in such a way that they will maintain themselves and the garbage collector won't have to operate too hard, and you won't have to tell it what things need deleting.
Page: 1 2