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

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

Asked by 5 years ago
Edited 5 years ago

NOTE - This is a re-post/duplicate question to this here. Though it didn't get much of a response, (since I posted it @ 2:00 in the morning) so I'm asking this again.

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.

0
Don't duplicate a question. Zafirua 1348 — 5y
0
Well it didn't garner much of a response in the first place. Should I turn to the forums instead? LateralLace 297 — 5y
0
I believe the garbage collector won't pick up something as long as something else still references it Amiaa16 3227 — 5y
0
You could just do conditional:Destroy() in the do stuff area. theCJarmy7 1293 — 5y
View all comments (3 more)
0
`conditional.Event:Wait()` Why not set up a function instead of using a coroutine? TheeDeathCaster 2368 — 5y
0
Ah I see. I knew that connections to an instance wouldn't be broken until the object was destroyed or disconnected, though I just wanted to confirm that a referenced Instance that isn't parented to the datamodel wouldn't despawn or something. LateralLace 297 — 5y

Answer this question