Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Will the lua garbage collector pick up an Instance that isn't parented to anything after awhile?

Asked by 5 years ago
Edited 5 years ago

I was wondering this as I wanted a more precise solution to yielding a thread. Consider this:

Instead of doing this

local conditional

spawn(function()
    repeat wait() until conditional
    --do stuff
end)

wait(1)
conditional = true

One could do this:

local conditional = Instance.new("BindableEvent")

spawn(function()
    conditional.Event:Wait()
    --do stuff
end)
wait(1)
conditional:Fire()

Though wan't fully sure if an instance not parented to the DataModel would automaticly despawn and get removed after awhile.

Answer this question