When are tables GC'ed?

Lets say for example I hold a reference to a character in a table located in a starter character script, when this scripts gets destroyed will the tables inside of it get GC’ed as well, or do I need to manually remove the reference to character from the table when the character is destroyed to ensure that the character gets GC’ed

You need to manually remove the reference from the table when the character is destroyed.

1 Like

Ok, but the issue I’m having is that i am trying to also do this with a tool, but the ancestry changed event is not firing when the parent is nil, so I have no way of knowing when its destroy so I can destroy my custom objects, thereby removing references to instances.

Just like any other object, they are eligible for garbage collection when there is no more strong references to that object. I say eligible because, the actual garbage collection process is not guaranteed to occur immediately upon the last strong reference no longer existing. Lua only guarantees that process may happen at any time following the loss of the last reference to the object. But Lua may also decide to trigger a garbage collection process at any point during your code’s execution because it deems it is running low on memory, for instance.

1 Like

I’m just now realizing, will the script still even run if its destroyed?

No, a script won’t run if it is destroyed.