What happens to non-parented instances, and is there a way to use them efficiently?

Topic

What happens to created objects that are created with Instance.new() or :Clone(), but are never parented using the .Parent argument?

Questions & Theories

I’m interested to know what happens if for example, I clone a Part, and set its .Position and .Size, but never actually Parent the part.

Can I still cast rays from the .Position of the Part, even though its .Parent isn’t ever being set to anything, and not have to worry about using :Destroy() to later remove the Part in order to stop a memory leak from the buildup of parts?

Could this even slightly boost performance, and is it better than simply setting a Part’s .Transparency to 1 in order to never render it, and then using :Destroy() on it?

According to Roblox, setting a Part’s .Parent to nil causes it to be “temporarily removed”, what does that mean?

1 Like

I do believe this is the same when you use Instance.new() as well, and you can manage change its properties but I don’t believe you can actually use it with other scripts (Unless if you call WaitForChild())

I believe it’s just a placeholder for it, not sure though

You can later reparent it somewhere(eg workspace) as long as you have the variable that references the part. It will not be completely removed by gc

What if I don’t want to reparent the Part anywhere, as this makes me have to call :Destroy() (this uses up more memory).

Would there be a performance boost if I just never Parented the Part, but still cast rays from it?

wdym by that? You don’t need a part for raycasting

Let’s say I want to grab the Part’s .Position for the [origin] argument that’s needed for raycasting. Would it boost performance if I never set the .Parent, but just used the Part to grab the .Position?

I am not sure if that will even work or not, it might. But why can’t you just have a vector3 value if you only wanted the position? Instancing a part is pretty expensive

That’s why I’m asking this in the first place.

This would be the best way to do it, but I’m just giving a scenario.

tested in a baseplate, it works

1 Like

Thank you for testing it. I will mark you as the solution.

1 Like