lua-users home
lua-l archive

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


Hi,

Christian Vogler wrote:
> WORKDIR = "foo"
> FILETOTRACK = "bar"
> dosomething(WORKDIR .. "/" .. FILETOTRACK)
> 
> dosomething() is a C function that stores a char * pointer to the string,
> which needs to be valid even after this function returns.
> 
> What is the lifetime of the string passed to dosomething()? Will it
> eventually be garbage-collected sometime after dosomething() has
> returned? So, would dosomething() have to make a copy of the string?

The string will be garbage collected.  But you can create a reference
to it so that it will not be garbage collected.  Look for lua_ref() in
the manual.  Of course, you have to lua_unref() it later or you'll get
memory leaks.

Ciao, ET.