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

Object got inserted into a table, Object got destroyed, Table stays as original O_O?

Asked by 6 years ago

Is there a way I can detect the object is destroyed?

Experiment script:

local mytable = {} 
local part = workspace.Part 
table.insert(mytable,part) 
print(#mytable) --Prints 1 '_'
part:Destroy() 
print(#mytable) --Prints 1? 0_0
print(mytable[1]) --Prints Part? O_O
0
Fluff my stupid brain! I just only have to check the parent is nil or not. magicguy78942 238 — 6y

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago

You're maintaining a reference to the part, which will prevent it from being garbage collected, and mytable hasn't been garbage collected when you run your prints.

You could remove it from the table yourself, or use a weak table with the values being weak (__mode = "v"):

http://wiki.roblox.com/index.php/Weak_tables

Ad

Answer this question