Just to be sure, if I create an instance using Instance.new() without parenting the instance to anything, would I still need to call :Destroy() to prevent memory leaks from occurring, or will the instance be garbage collected after the reference variable falls out of scope?
Thanks to anyone who may know this. I’m pretty sure :Destroy() is not required here, but if someone else could enlighten me about the engine internals that would be great.
In this situation you should still call :Destroy() on the object.
It is important to destroy an object regardless of it having a parent, since the destroy function will disconnect all connections, and destroy all children parented to the object (which both use memory, leading to a memory leak if unused)
If I remember correctly, an unparented “parent” object can still have children objects. For example “Part A” is parented to nothing (aka nil) and “Part B” is parented to “Part A.”
The only way to clear up memory of “Part B” (if you plan to no longer use “Part A” or “Part B”) would be to call destroy on “Part A.”
I can’t comment on if the garbage collector would do this for you. Though I would advise that you call the destroy function when you’ve finished using an object regardless of it having a parent as good practice.