lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Roughly speaking, when you load the script you get a function returned on
the Lua stack.  When you pop it from the Lua stack it will then be a
candidate for garbage collection and in its next pass the garbage collector
will "remove it".  If you don't want this to happen then you will need to
store a reference to the function in the Lua globals table, or registry.

When you call the function that resulted from loading the script it can add
things to the globals table and thus consume more memory.  For instance,
running the following script segment will add a function and a table to the
globals table and thus consume some memory...

function Foo()
   print("This is a function")
end

Bar = { 1, 2, 3 }


----
However, running this script segment will NOT add anything to the globals
table, and thus the process of RUNNING this script will not cause any memory
to be consumed....

print("This script doesn't create or modify any variables")
print("2 times 2 is ", 4)




-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br]On Behalf Of Tharo Herberg
Sent: Tuesday, August 03, 2004 2:06 PM
To: Lua list
Subject: Memory load


Hm ... im new at lea so plz dont kill e for my newbie question.

We want to use lea for smal scriptings in level maps. It runs well,
funtion including was also no problem.
When i load now the script for field xy ... When i load it as function and
call it from c it stays in ram, right? When i just write scriptcode down
it is cleared from stack and from ram after running it, or?

How can i "remove" functions or code from ram after the player left my
map? I only have 8 MB for everything so this is very importand for me.

thx

Tharo