destroy a variable

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

destroy a variable

Luo Hei
I have found a weird problem while writing my server.
If I repeatedly execute the string "a=math.random(1,20)" in my embedded interpreter, when I stop the host I got a crash with a lot of glibc errors. If I replace the code by "math.random(1,20)" no problems occurs. Is there any way to destroy variables used in an script when I dont need them anymore?

--
http://dsgp.blogspot.com | Linux, programación, juegos
Have no place I can be since I found Serenity
But you can’t take the sky from me

		
______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Luiz Henrique de Figueiredo
> If I repeatedly execute the string "a=math.random(1,20)" in my embedded 
> interpreter, when I stop the host I got a crash with a lot of glibc 
> errors.

Perhaps you're overflowing the stack? It shouldn't happen. Can you post
code? A minimal example would help.

> If I replace the code by "math.random(1,20)" no problems occurs. 

Overflowing the stack does not explain this.

> Is there any way to destroy variables used in an script when I dont need 
> them anymore?

Set them to nil, but you shouldn't have to do that.
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

David KOENIG
In reply to this post by Luo Hei
Roger D Vargas wrote:
> I have found a weird problem while writing my server.
> If I repeatedly execute the string "a=math.random(1,20)" in my
> embedded interpreter, when I stop the host I got a crash with a lot of
> glibc errors. If I replace the code by "math.random(1,20)" no problems
> occurs. Is there any way to destroy variables used in an script when I
> dont need them anymore?
>
Try: foo = nil

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Luo Hei
In reply to this post by Luiz Henrique de Figueiredo


Luiz Henrique de Figueiredo escribió:
If I repeatedly execute the string "a=math.random(1,20)" in my embedded interpreter, when I stop the host I got a crash with a lot of glibc errors.

Perhaps you're overflowing the stack? It shouldn't happen. Can you post
code? A minimal example would help.
This is the code that executes the string
void ScriptEngine::exec(string str)
{
    if (str.length() > 0) {
int error = luaL_loadbuffer(luaVM, str.c_str(), str.length(), "line") || lua_pcall(luaVM, 0, 0, 0);
            if (error) {
                cout << lua_tostring(luaVM, -1) << endl;
                lua_pop(luaVM, 1);
            }
    }
}

In my code I simply do this, as a basic stress test:

scInt->exec("a=math.random(1,20)");


If I replace the code by "math.random(1,20)" no problems occurs.

Overflowing the stack does not explain this.

Is there any way to destroy variables used in an script when I dont need them anymore?

Set them to nil, but you shouldn't have to do that.
--lhf


--
http://dsgp.blogspot.com | Linux, programación, juegos
Have no place I can be since I found Serenity
But you can’t take the sky from me

		
______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Luiz Henrique de Figueiredo
> If I repeatedly execute the string "a=math.random(1,20)" in my embedded 
> interpreter, when I stop the host I got a crash with a lot of glibc 
> errors.

I could not reproduce this. Can anyone? What glibc errors do you get?
--lhf

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Zachary P. Landau-4
In reply to this post by Luo Hei
On 4/29/07, Roger D Vargas <[hidden email]> wrote:
I have found a weird problem while writing my server.
If I repeatedly execute the string "a=math.random(1,20)" in my embedded
interpreter, when I stop the host I got a crash with a lot of glibc
errors. If I replace the code by "math.random(1,20)" no problems occurs.
Is there any way to destroy variables used in an script when I dont need
them anymore?

Is this on some low-memory device?  I wonder if it is possible that
you are allocating memory faster than the garbage collector can
reclaim it.  Although I wouldn't expect  "a=math.random(1,20)" and
"math.random(1,20)" to be significantly different as far as memory
allocation is concerned.

--
Zachary P. Landau <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Luo Hei
In reply to this post by Luiz Henrique de Figueiredo
I cant reproduce it neither here at office. I will try to get it at home next weeked, but the error refers to some double linked list corruption. I thought it was due to a mistake handling a hash_map, but the error ceased when I changed the lua code.


Luiz Henrique de Figueiredo escribió:
If I repeatedly execute the string "a=math.random(1,20)" in my embedded interpreter, when I stop the host I got a crash with a lot of glibc errors.

I could not reproduce this. Can anyone? What glibc errors do you get?
--lhf


--
http://dsgp.blogspot.com | Linux, programación, juegos
Have no place I can be since I found Serenity
But you can’t take the sky from me

		
______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Luo Hei
In reply to this post by Zachary P. Landau-4


Zachary P. Landau escribió:
On 4/29/07, Roger D Vargas <[hidden email]> wrote:


Is this on some low-memory device?  I wonder if it is possible that
you are allocating memory faster than the garbage collector can
reclaim it.  Although I wouldn't expect  "a=math.random(1,20)" and
"math.random(1,20)" to be significantly different as far as memory
allocation is concerned.

No, it is a linux box with 256 Mb and usual services for a workstation. The code runs inside a loop executed probably 100 times per second.


--
http://dsgp.blogspot.com | Linux, programación, juegos
Have no place I can be since I found Serenity
But you can’t take the sky from me

		
______________________________________________ LLama Gratis a cualquier PC del Mundo. Llamadas a fijos y móviles desde 1 céntimo por minuto. http://es.voice.yahoo.com

Reply | Threaded
Open this post in threaded view
|

Re: destroy a variable

Zachary P. Landau-4
In reply to this post by Luo Hei
On 4/30/07, Roger D Vargas <[hidden email]> wrote:
I cant reproduce it neither here at office. I will try to get it at home
next weeked, but the error refers to some double linked list corruption.
I thought it was due to a mistake handling a hash_map, but the error
ceased when I changed the lua code.

I've seen this error here and there in other applications, although I
don't think it does much to help you narrow down the cause.  If you're
up for it, running it under Valgrind may provide the answer.

--
Zachary P. Landau <[hidden email]>