查找Lua中对象的所有引用 [英] Find all references to an object in Lua
问题描述
collectgarbage(collect)
)。我假设这意味着我有一个悬挂的参考。 那么我如何获取一个对象的各种引用的位置的列表?例如:
obj = MyObject()
ref = obj
tbl = {obj}
obj = nil
print(getreferences(obj)) - 应该打印像_G.ref,_G.tbl [1]
我将简单地为此编写自己的函数,但是它将无法找到包含在闭包中的引用。任何建议?
有一个工具来遍历整个Lua宇宙。请参阅 http://lua-users.org/lists/lua- l / 2006-07 / msg00110.html
I have a memory leak in the Lua part of my application. For whatever reason, my object is not getting deleted when it should (even when I call collectgarbage("collect")
). I assume this means I have a dangling reference somewhere.
So how may I obtain a list of where various references to an object reside? For example:
obj = MyObject()
ref = obj
tbl = {obj}
obj = nil
print(getreferences(obj)) -- should print something like _G.ref, _G.tbl[1]
I would simply write my own function for this, but it would not be able to find references contained inside of closures. Any advice?
There's a tool to traverse the whole Lua universe. See http://lua-users.org/lists/lua-l/2006-07/msg00110.html
这篇关于查找Lua中对象的所有引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!