Will this userdata be garbage collected?

Not too important but would userdata who have been cleared from tables be garbage collected?

The script I use is a bit complicated so I’ll just create a simple version of what I’m doing

local module= {}

module.Stores= {}

function module.new(name)
  local thing = newproxy(true)
  local proxy = {}
  local meta = getmetatable(thing)
  
  proxy.Name = name

  meta.__tostring = function(t) return t.Name end
  meta.__index = proxy
  
  module.Stores[thing.Name] = thing -- store it in a table

  return thing

end

-- later somewhen

module.Stores[name] = nil -- will it be removed from memory

Will the userdata along with the proxy data and metatable be garbage collected too?

I’m only asking this since I don’t want massive memory leaks in my game.

Edit: Also if there were no other references to it besides that table would it be removed?

1 Like