- Joined
- Mar 26, 2017
- Messages
- 376
Making a table weak valued allows handle indices that are held in a lua table to be recycled, even though they are still kept in the lua table.
I see in an empty map, that a unit handle gets recycled ~12 seconds after the unit is removed. If the line above is not called, the unit handle never gets recycled, as the lua table reference prevents handle recycling.
I don't know if this is widely used, but it seems useful for (unit) indexing applications. With weak valued tables, it is no longer needed to nil entries when their corresponding game objects get removed.
Lua:
setmetatable(<table name>, {__mode = 'v'})
I see in an empty map, that a unit handle gets recycled ~12 seconds after the unit is removed. If the line above is not called, the unit handle never gets recycled, as the lua table reference prevents handle recycling.
I don't know if this is widely used, but it seems useful for (unit) indexing applications. With weak valued tables, it is no longer needed to nil entries when their corresponding game objects get removed.