I’m not sure if this has been talked about. But my concern is that when I clone an instance (GUI frame) and destroy it, It doesn’t seem to be completely “destroyed” until I manually set the instance to nil. Here’s a simple code
local Template = script.Template:Clone()
Template.Parent = RewardFrame
task.delay(5, function()
Template:Destroy()
--Template = nil --free client memory?
print(Template) --either name of instance or nil (if uncommented)
end)
I don’t see many cases regarding this in most resources (or even games). Perhaps it’s just a minor issue? Should I ever be worried about it?
I was just dealing with this beforehand (in both client and server), and it’s simply because the instance doesn’t get destroyed fast enough. Put a task.wait() between the two and adjust it if necessary and see if it prints nil.
Ah, it appears I was wrong (I have set the instance to nil). The Documentation for Instance:Destroy() strictly says to make the instance nil when it’s destroyed to avoid the template from being called again.
I see. I guess it’s just a way to prevent from an instance being accessed further by script, but never mentioning “memory leak” from setting it nil. So that would be my least concern, maybe.
Reading the documentation, not setting it to nil won’t lead to memory leaks. So there’s really nothing to worry about; Set it to nil if you believe you won’t need to use it again anymore.