If anyone is proficient in this area of the topic, please offer some insights.
Is it more memory efficient to store data inside a function and only call that function when needed to retrieve the data into the scope and let it garbage collect when the data is no longer in scope?
I have a lot of data for loot and items currently stored in tables and I’m wondering if I should move them into functions because the data isn’t created until the function is called? I’m not sure if that’s right.
debug.setmemorycategory("TableStyleMem");
local itemsTableMem = {
{Id="itemA"; Description="This is item a."; StackSize=32; Type="Food"};
{Id="itemB"; Description="This is item b."; StackSize=31; Type="Food"};
{Id="itemC"; Description="This is item c."; StackSize=30; Type="Tool"};
{Id="itemD"; Description="This is item d."; StackSize=29; Type="Tool"};
{Id="itemE"; Description="This is item e."; StackSize=28; Type="Resource"};
}
local retrieveItemA = itemsTableMem[1];
debug.setmemorycategory("FunctionStyleMem");
local itemFunctionMem = {
function() return {Id="itemA"; Description="This is item a."; StackSize=32; Type="Food"} end;
function() return {Id="itemB"; Description="This is item b."; StackSize=31; Type="Food"} end;
function() return {Id="itemC"; Description="This is item c."; StackSize=30; Type="Tool"} end;
function() return {Id="itemD"; Description="This is item d."; StackSize=29; Type="Tool"} end;
function() return {Id="itemE"; Description="This is item e."; StackSize=28; Type="Resource"} end;
}
local retrieveItemA = itemFunctionMem[1]();
According to memory categories, it shows a difference here… But I’m wondering where are the values within the function is stored and how much memory that takes up.