When is the Player object removed?

Im currently trying to find memory leaks in my game. Given I store quite a few things inside the player object I would need to know: When is it destroyed?

It’s obviously still there for some time to allow playerremoving to run, but how long until it’s completely GCed?

1 Like

It should not be GC’d as long as you have a reference to it in Lua.

As with the nature of garbage collection, it is essentially random. Instances are destroyed when the garbage collector gets around to them, provided you have no lingering references to the Instances.

So roblox doesn’t have any player:Destroy() call?

More like a Player.Parent = nil call

Also, there was a recent thread discussing this that might help:

Destroying an object does not set Lua references to it to nil, this would make for very inconvenient programming if that were the case. As long as you have a reference to the Player object somewhere, it still exists because it is referenced.

1 Like

you can do Player:Destroy()

just try it you’ll see what happens.

(It’s like you left the game but you haven’t)

But atleast it deletes the objects children?

Just tested in studio. No direct children are removed (backpack,gui,etc), so I assume none are removed.

I tested it too but with adding another folder, that folder got removed.