I read that dictionaries in lua are never garbage collected. Currently I am just going through and clearing every existing key of a dictionary through the pairs iterator when I'm done using it to prevent memory leaks, but that isn't very efficient. Is there a way to just set a dictionary to nil without having to manually clear every key/value pair?
COMMUNITY QUESTION
How to delete a dictionary?
0 answers
No public answers were preserved for this question.
This discussion is preserved as it was. New answers, comments, and votes are closed.

9 comments
Are you talking about tables like this{}
Yeah. A dictionary is where you store values by strings instead of by index. For example: foo = {["A"] = "Apple", ["B"] = "Baseball", ["C"] = "Cat"}
And are you sure you cant just use foo = nil foo = {}
If you do that it just changes where the variable foo is pointing to. As far as i'm aware dictionaries aren't garbage collected, so removing all references from the dictionary wouldn't delete it from memory.
Could you use a faster loop like for i = 1,#foo do local v = foo[i] end
No, because the values are stored under keys. The only way to iterate by key is to use the pairs iterator, unless I made another table that stored every key in the dictionary. I'm not sure if that's more efficient.
Then im 90% sure there is no better way, roblox needs to fix this.
It's more of a lua problem. There's no 'clear' method in the table library as it stands. I read to make one yourself you have to make it in C, and I don't think that's possible in roblox.
Oh.