Removing from Lua dictionary

Started by
2 comments, last by Merick Zero 16 years, 1 month ago
Hello. I'm trying to remove an entry from a Lua table indexed with strings. If the Lua table were indexed by number, I could type table.remove(table, index) where index is a number. But the Lua compiler I'm using won't let me pass in a string as the index in the table.remove function. I need to remove old entries from a string-indexed table to avoid memory leaks. What do I do?
Advertisement
you can do "mytable[index] = nil", it won't remove the index key from the table like table.remove would, but as long as there are no other refrences to the data at that index then it will be removed from memory by the garbage collector.
Quote:Original post by Merick Zero
you can do "mytable[index] = nil", it won't remove the index key from the table

Sure it will. Keys whose values are set to nil are identical to keys which are not present.
ahh! I hadn't realized that, I had been thinking that a key which was explicitly set to nil would still remain in the table

This topic is closed to new replies.

Advertisement