[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: measuring memory consumptions
- From: Matthew Wild <mwild1@...>
- Date: Mon, 19 Jul 2010 12:07:51 +0100
On 19 July 2010 10:30, Valerio Schiavoni <valerio.schiavoni@gmail.com> wrote:
> Hello again,
> i've got it working. The problem with is that it doesn't take into
> account referenced objects:
>
> require"getsize"
> debug=require'debug'
>
> a={1,2,3}
> b={1,2,3,4,5,6,7}
> c={a,b}
> print(debug.getsize(a)) -- 152
> print(debug.getsize(b)) -- 216
> print(debug.getsize(c)) -- 136 !!
>
Correct. Your goal of calculating the RAM usage of a particular module
is a very difficult one indeed.
Consider:
a = { 1, 2, 3 }
b = { 1, 2, 3, 4, 5, 6, 7 }
c = { a, b }
d = { a, b }
e = { a, b, c, d }
Now... if you calculate the size for e with referenced objects you
will get e+a+b+c+(a+b)+d+(a+b). Note that a and b are being added to
the total multiple times - but they only occupy space in RAM once.
In the context of modules... if two modules in your app reference the
same 10MB string... which module will you say is using that 10MB of
RAM? or will you say that together they are both using 20MB when they
are each using the same 10MB? It's not easy :)
However you may be interested in a project I use a lot with getsize:
http://code.matthewwild.co.uk/luatraverse/
It can traverse objects in the Lua state, and tell you which objects
they reference (including table keys/values, function upvalues,
metatables, etc.). I primarily use it to check for memory leaks, as it
can indicate tables that are larger than they ought to be.
Regards,
Matthew