alright, so, if i make a table and decide to make the keys all instances, would that be bad? ive saw some posts say that you shouldnt do this, as it will cause memory leaks, but why wouldnt i just do something like…
local temporarytable = {}
local awesomeinstance = Instance.new("Part")
awesomeinstance.Parent = workspace
temporarytable[awesomeinstance] = {firstvalue = 0, secondvalue = 21}
awesomeinstance.AncestryChanged:Connect(function() if not awesomeinstance.Parent then temporarytable[awesomeinstance] = nil end end)
would this be alright? will i cause a massive memory leak? please help me.
I think what you’re doing is fine. You’re holding a reference to the instance and using it to clear out the entry in the table.
The only way I can see a memory leak becoming an issue is if you no longer have a reference to the instance in order to clear out the entry in the table.