Small question over garbage collection

I am just wondering if the following boolvalue gets automatically garbage collected (destroyed) when the table gets cleared or set to nil

BoolTable = {

BoolVal = Instance.New("BoolValue")
}

wait(5)

table.clear(BoolTable)
--or
BoolTable=nil
BoolTable={}

or would I have to manually :Destroy the object

No, all instances, even when unattached to the DataModel, will not be gc’d unless they are destroyed and have no strong references (The table is cleared).

You can test things like this using gcinfo().

while true do
	task.wait()
	Instance.new("BoolValue") -- Without this, the memory stays the same.
	print(gcinfo())
end
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.