[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: lifetime of strings
- From: Edgar Toernig <froese@...>
- Date: Mon, 04 Sep 2000 15:24:47 +0200
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.