title: How to handle Lua memory/references if my userdata is used as a key elsewhere?
body: <p>I am indexing some table with my userdata (lets call it Turret) - to store some associated variables like bullets and armor.
  I need to manage Turret's lifecycle by being able to set it to nil, subsequently allowing Lua to GC it. I'm worried that I lose all control over the object's memory when I use it as a key elsewhere.</p>
  
  <p>Sample Code:</p>
  
  <pre><code>local turretStorage = {}
  
  -- Bunch of turrets are created and added, lets look at the one below
  
  local turret = load.newTurret(15) -- Create a Turret userdata
  turretStorage[turret] = {}
  turretStorage[turret].bullets = 100
  turretStorage[turret].decal = "skulls.png"
  
  -- Some time passes, we're done with the turret object
  turretStorage[turret] = nil
  turret = nil
  </code></pre>
  
  <p>My concern is the indexing of turretStorage by turret userdata. Does turret userdata ever get GC'd? If setting the turretStorage[..] to nil removes the key references - could you please show me supporting documents?</p>
  
  <p>Should I somehow nil the key in the turretStorage table? If so, how would I do it?</p>
  
  <p>If the key is used as a reference of the original variable and can't be removed, then I am stuck and need help, or refactoring.</p>
  
  <p>If the key in this example is just userdata's memory location used as a unique index - then I'm completely in the clear; but - the answered question would have references to support this ;)</p>