To keep it simple, I have a module that has a table referenced, created with table.create(1000, nil) in this example, I recently started using LuauHeap in the developer console to detect memory leaks, but with this, I notice that the empty table has memory allocated to it, after using table.clear() on it too, memory doesn’t seem to decrease.
Is this a way to reserve memory that doesn’t actually exist and ends up counting as actual memory, or an actual bug?
its probably because if you do table.create(1000) then you should intend to use 1000 values and so they made it allocate the memory, but if you just set it to an empty table {} then you can have sparse indices without using memory
It would make sense. Would it be normal behavior that the allocated memory doesn’t lower after certain time? and would there be another way (besides setting the table to a new one, I assume) to get rid of the allocated memory?
The point of table.create is to pre-allocate memory before filling it so that you can avoid unnecessary reallocations.
The reason table.clear doesn’t free the memory is because there is no extra information stored internally with the table about what allocated memory it has (because that would incur a significant cost for all tables).
It should be collected when the next cycle runs afterwards, though.
The GC runs based off a pacer algorithm that picks which opportune times to sweep and is very fined tuned for different hosts. As far as I know, the specific settings Roblox uses for their VM implementation isn’t documented and could easily change in the future.
Also, for clarity, Luau does not have emergency GC (when the host is running low on memory). That’s for the embedder to take care of.