From GMod Wiki
|Lua: Garbage Collection|
|Description:||Explains Garbage Collection in Lua|
|Created:||2nd December 2006|
Garbage collection refers to the set of algorithms used to automatically delete variables which are no longer reachable, i.e., the variables can no longer be accessed by the program.
Whenever Lua's garbage collector is run, it determines which objects are accessible, and the remaining objects are automatically destroyed.
The __gc metamethod is part of an object's metatable and cannot be executed directly - it is called when the garbage collector runs, and determines the object to which the metamethod belongs is unreachable.