Will tables take memory, if their parent table is nilled?

Hello guys. I’m making my tree generator. It uses system like this:

local Tree = {
	Trunk = {
		Trunk = {
			Trunk = {},
			Trunk = {},
			Trunk = {},
		},
		Trunk = {
			Trunk = {},
			Trunk = {},
		},
	},
}

So, there’s tree trunks parented to each other. Let’s say I want delete Tree:

Tree = nil

Will after this Trunk tables persist, if there’s no any other links to them, other than that Tree table which got nullified?

By setting Tree = nil, you are completely deleting the dictionary it holds. Because the dictionary ceases to exist

When a reference is lost to a variable in lua, it becomes dead and is collected during the next cycle.
In other words, the memory the variable was using is either freed or reused when you lose reference to the variable.

1 Like