garbage collection - How to handle Lua memory/references if my userdata is used as a key elsewhere? -
garbage collection - How to handle Lua memory/references if my userdata is used as a key elsewhere? -
i indexing table userdata (lets phone call turret) - store associated variables bullets , armor. need manage turret's lifecycle beingness able set nil, subsequently allowing lua gc it. i'm worried lose command on object's memory when utilize key elsewhere.
sample code:
local turretstorage = {} -- bunch of turrets created , added, lets @ 1 below local turret = load.newturret(15) -- create turret userdata turretstorage[turret] = {} turretstorage[turret].bullets = 100 turretstorage[turret].decal = "skulls.png" -- time passes, we're done turret object turretstorage[turret] = nil turret = nil
my concern indexing of turretstorage turret userdata. turret userdata ever gc'd? if setting turretstorage[..] nil removes key references - please show me supporting documents?
should somehow nil key in turretstorage table? if so, how it?
if key used reference of original variable , can't removed, stuck , need help, or refactoring.
if key in illustration userdata's memory location used unique index - i'm in clear; - answered question have references back upwards ;)
an object in lua considered garbage , marked collection when there no references within lua. using value key in table counts reference.
consider using weak tables if fit design.
lua garbage-collection lua-table
Comments
Post a Comment