Lua garbage collection tables nested tables

[I read the Lua manual, but it did not give reliable answers.]

Let's say I have a Lua table acting like an indexed array:

local myArray = {};
myArray[1] = "Foo";
myArray[2] = "Bar";

What is the best way to manage this table? Am I just setting myArray to nil? Or do I need to iterate over the array and set each indexed item to zero?

Similarly, let's say I have a Lua table acting like a dictionary:

local myDictionary = {};
myDictionary["key1"] = "Foo";
myDictionary["key2"] = "Bar";

Can I just set 'myDictionary' to nil or do I need to iterate?

Finally, what should I do, memory management wisely, where do I have nested tables? eg.

local myNestedCollection = {};
myNestedCollection[1] = {1, 2, 3};
myNestedCollection[2] = {4, 5, 6};

Do I need to iterate over each of these sub-tables, setting them to zero? Thanks for any help.

+3
2

GC , . . , .

+5

nil; nil to. , Lua . nil, , . , , , .

+6

Source: https://habr.com/ru/post/1710648/


All Articles