开源软件名称(OpenSource Name):yaukeywang/LuaMemorySnapshotDump开源软件地址(OpenSource Url):https://github.com/yaukeywang/LuaMemorySnapshotDump开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):LuaMemorySnapshotDumpLua memory snapshot dump utility, used for memory leak detection。 About
UsageFirst of all, you need to require local mri = require(MemoryReferenceInfo) Next step, you need to dump the lua memory snapshot at first time somewhere: -- Before dumping, collect garbage first.
collectgarbage("collect")
mri.m_cMethods.DumpMemorySnapshot("./", "1-Before", -1)
By default, -- Setting the config not add time stamp at the end of the file name.
mri.m_cConfig.m_bAllMemoryRefFileAddTime = false
Generally, you need to set this config at the very begining just below the How to read the result? All references are lined, and seperated by tab into 3 columns which are type:address/name, reference chain, reference count. Lines are sorted by references count in descend. So, you can open this result file by For example: As you want to check the memory leak, so you need another memory snapshot to see if it is bigger than the older one, even you need to compare this with the older one to see what exactly increased. So, after running some time, it's time to take another memory snapshot: -- Dump memory snapshot again.
collectgarbage("collect")
mri.m_cMethods.DumpMemorySnapshot("./", "2-After", -1)
Now, you have two files stored in your current directory, named: Then, you can now compare the two files to see the increased data: mri.m_cMethods.DumpMemorySnapshotComparedFile("./", "Compared", -1,
"./LuaMemRefInfo-All-[1-Before].txt",
"./LuaMemRefInfo-All-[2-After].txt")
This output a file named like Sometimes, you want to find all the references of an object(table, function, userdata, thread, string), you can do this: -- Find all the references who referenced object "_G.Author".
collectgarbage("collect")
mri.m_cMethods.DumpMemorySnapshotSingleObject("./", "SingleObjRef-Object", -1, "Author", _G.Author)
You can also find string references like this: -- Find all the references who referenced string "yaukeywang".
collectgarbage("collect")
mri.m_cMethods.DumpMemorySnapshotSingleObject("./", "SingleObjRef-String", -1, "Author Name", "yaukeywang")
The output results will show all the details for that. In large project, due to the complex of the lua state, the result file may be pretty lary, but you can do this to filter the data: -- Filter all content that include the keyword "Author" (ignore case), and save as a new file.
mri.m_cBases.OutputFilteredResult("./LuaMemRefInfo-All-[2-After].txt", "Author", true, true)
-- Filter all content that exclude the keyword "Author" (ignore case), and save as a new file.
mri.m_cBases.OutputFilteredResult("./LuaMemRefInfo-All-[2-After].txt", "Author", false, true)
With these utilities, i think you can fix the memory leak quickly. MoreFor method -- Only dump memory snapshot searched from "_G".
collectgarbage("collect")
mri.m_cMethods.DumpMemorySnapshot("./", "1-Before", -1, "_G", _G)
It will only dump the memory snapshot in "_G". NoteIn order to display the |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论