Skip to content

Instantly share code, notes, and snippets.

@dphfox
Created August 12, 2021 07:56
Show Gist options
  • Save dphfox/59714ae885a2a0b4d1d1c01f3dcb449f to your computer and use it in GitHub Desktop.
Save dphfox/59714ae885a2a0b4d1d1c01f3dcb449f to your computer and use it in GitHub Desktop.
Roblox GC issue
local function new()
local ref = {instance = Instance.new("TextButton")}
ref.instance.Parent = workspace
local function updateRefStrength()
if game:IsAncestorOf(ref.instance) then
setmetatable(ref, {})
else
setmetatable(ref, {__mode = "v"})
end
end
task.defer(updateRefStrength)
ref.instance.AncestryChanged:Connect(updateRefStrength)
ref.instance.Activated:Connect(function()
print(ref.instance.Name)
end)
return ref.instance
end
local ref = setmetatable({new()}, {__mode = "v"})
delay(5, function()
print("moving to nil!")
ref[1].Parent = nil
end)
while ref[1] do
print("still alive...")
wait(1)
end
print("gone!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment