Memory leaks most probably called by multiple lua_dobuffer

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory leaks most probably called by multiple lua_dobuffer

terenctb
Just writing to see if anybody has done something like this before. I 
think is causing our program to leak memory slowly because we are 
confusing lua.

What we have done is basically written a C-function called by lua 
which passes a ID refering to another lua script so that we could 
call another lua script from lua..i.e. script 1 runs...executes our 
funcition which executes another lua script using the same L state 
pointer and then returns to the original script which continues..

Not sure if this would cause a leak in lua, but I think it is and I 
just wanted to check before I get alot of our script re-written to 
find out it isn't.

Terence


Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks most probably called by multiple lua_dobuffer

Luiz Henrique de Figueiredo
>Just writing to see if anybody has done something like this before. I 
>think is causing our program to leak memory slowly because we are 
>confusing lua.
>
>What we have done is basically written a C-function called by lua 
>which passes a ID refering to another lua script so that we could 
>call another lua script from lua..i.e. script 1 runs...executes our 
>funcition which executes another lua script using the same L state 
>pointer and then returns to the original script which continues..
>
>Not sure if this would cause a leak in lua, but I think it is and I 
>just wanted to check before I get alot of our script re-written to 
>find out it isn't.

Please give more details. You mentioned lua_dobuffer in the Subject
but not in the body. Are you running precompiled code or text in those
buffers?
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks most probably called by multiple lua_dobuffer

terenctb
--- In lua-l@y..., Luiz Henrique de Figueiredo <lhf@t...> wrote:
> >Just writing to see if anybody has done something like this 
before. I 
> >think is causing our program to leak memory slowly because we are 
> >confusing lua.
> >
> >What we have done is basically written a C-function called by lua 
> >which passes a ID refering to another lua script so that we could 
> >call another lua script from lua..i.e. script 1 runs...executes 
our 
> >funcition which executes another lua script using the same L state 
> >pointer and then returns to the original script which continues..
> >
> >Not sure if this would cause a leak in lua, but I think it is and 
I 
> >just wanted to check before I get alot of our script re-written to 
> >find out it isn't.
> 
> Please give more details. You mentioned lua_dobuffer in the Subject
> but not in the body. Are you running precompiled code or text in 
those
> buffers?
> --lhf
We are running pre-compiled code. We wanted a way to 'modularize' our 
code.
Basically we are:
1) Getting a pre-compiled buffer area(hashed via an id)
2) running it using lua_dobuffer
3) In the script it may call out to C function which
   will get another piece of pre-compiled code which get executed
(using the same L state passed to the C function)
4) returns to the main 'calling script'

Not sure if this would be any help but I am doing a lua_gettop(L)
and lua_settop(L) before and after the lua_dobuffer just to reset the 
stack(I saw this some where before for fixing memory leaks).

Hope this is enough info

Terence



Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks most probably called by multiple lua_dobuffer

Luiz Henrique de Figueiredo
In reply to this post by terenctb
>Basically we are:
>1) Getting a pre-compiled buffer area(hashed via an id)
>2) running it using lua_dobuffer
>3) In the script it may call out to C function which
>   will get another piece of pre-compiled code which get executed
>(using the same L state passed to the C function)
>4) returns to the main 'calling script'

Every time you call lua_dobuffer, many things are allocated (it does not
really matter whether the buffers contain pre-compiled code or source text),
even if you call lua_dobuffer on the same buffer more than once. Of course,
everything should be collected when it becomes garbage. There should be no
leak.

Bottom line: calling lua_dobuffer (or lua_dostring or lua_dofile) always
allocates memory to hold the objects created by the chunks executed by
this call. Did you expect otherwise?

On the other hand, we are aware that if you're running lua_dobuffer on
static buffers than you might expect that there would be no need to duplicate
the data there. This is a reasonable expectation but at present data is
duplicated. We are looking for a good solution to this problem, but like I
said, string values in Lua for instance assume that their string data and
their header data are contiguous but strings in pre-compiled chunks only
have the string data part, naturally.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: Memory leaks most probably called by multiple lua_dobuffer

Thatcher Ulrich
On Oct 17, 2002 at 04:26 -0200, Luiz Henrique de Figueiredo wrote:
> >Basically we are:
> >1) Getting a pre-compiled buffer area(hashed via an id)
> >2) running it using lua_dobuffer
> >3) In the script it may call out to C function which
> >   will get another piece of pre-compiled code which get executed
> >(using the same L state passed to the C function)
> >4) returns to the main 'calling script'

As a workaround (not really addressing any underlying problem), why
don't you associate a lua function with each ID, instead of a buffer?
So you'd use lua_call instead of lua_dobuffer to run your scripts.

-- 
Thatcher Ulrich
http://tulrich.com