[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Tracing Memory Grabbers
- From: Dimitris Papavasiliou <dpapavas@...>
- Date: Fri, 16 Mar 2012 12:55:46 +0200
> So I got a memory leak in my 64%-Lua, 35%-C Application.
Out of sheer curiosity, what's that remaining 1%?
> Whats the best way to determine as first step, if its a classical C
> leak in the 35% of forgetting some free(), or if its a reference I
> forgot to remove/set weak in a table in Lua, so its GC cannot collect?
> (I got a lot of tables with criss-cross referencing)
You can detect leaks by using Valgrind. Depending on the other
libraries used by your project you might have a hard time figuring out
which leaks are your own code's fault (most large third-party
libraries I've come across are literally littered with memory
allocation errors) but anyway Valgrind is the easiest and surest way
to go. It also allows finds other memory allocation related bugs like
reading/writing unalloc'd memory addresses etc.
Regarind leak testing Lua code, that depends on the code I suppose. I
keep all explicit references, which can cause leak errors in the
registry so a way to check is to see what keys exist in the registry
(by iterating the table) and compare it to what you would expect.
Dimitris
PS: I didn't give any details as to how to use Valgrind as there are a
lot of tutorials on the web and the documentation is pretty good.