Hello
I have an NPC model and a script inside.
In the script I create several objects, which are referenced only by local variables inside the script but are not parented to the NPC.
If I destroy the NPC, the script will be destroyed, but will these objects be garbage collected? (I am concerned about memory leaks).
I see that some people are using an artificial container called “maid”, but I am not sure if I need this…
The objects are not under the script, but they are referenced only by variables inside the script.
I understand that they will not be destroyed immediately, but my question is whether they will be garbage collected or I need to destroy them manually
As hbgnhu and mooonc0w said, the script isn’t the direct parent to the objects. Although, if you want to delete them you could probably put them in folders or a table and call :Destroy() from there… I’m not sure but it is an idea!
Since there is no reference to them, they will most like be garbage collected…
But creating and deleting scripts to remove variables isn’t good practice. If you don’t need the variables, don’t bother.