查找Lua中对象的所有引用 [英] Find all references to an object in Lua

查看:619
本文介绍了查找Lua中对象的所有引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆