Lua - Count the no. of references to a table

烂漫一生 提交于 2020-01-02 10:21:29

问题


The Lua docs say

When a program has no references to a table left, Lua memory management will eventually delete the table and reuse its memory.

My question is : Is it possible to count the no of references to a particular table during runtime?


回答1:


You can find all references to a Lua value using the debug library. See these messages:

  • http://lua-users.org/lists/lua-l/2012-03/msg00479.html
  • http://lua-users.org/lists/lua-l/2012-04/msg00758.html

The luatraverse library found in the below link solves this nicely! http://code.matthewwild.co.uk/luatraverse/summary



来源:https://stackoverflow.com/questions/11366693/lua-count-the-no-of-references-to-a-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!