lua-users home
lua-l archive

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


Hi Duke,

Yes, this is implicit as Denis wrote. Sooner or later the gc will collect this.

You can read some "clues" in these links:

https://www.lua.org/pil/2.4.html
https://www.lua.org/pil/3.4.html
https://www.lua.org/gems/sample.pdf (About strings)

This is pretty common (unless in Perl) but can cause a lot of confusion if presented too early to the student or are explained with "complex terms" (at least to me).
But again, probably I am the worst programmer in this list and most of time I don't have any idea what the guys are talking about xD

Best,

Em quinta-feira, 26 de maio de 2022 10:51:25 BRT, DENIS <denis@denis.com.br> escreveu:


the core of concept.

in lua (and many others languages) string are imutable (like java too)

any change of value of variable you can rehash it (recycle)

in c you can usage char array (static or dynamic)
static: char buf[128]
dynamic: malloc/calloc





---- Em Qui, 26 mai 2022 09:18:55 -0300 Duke Normandin <dukeofpurl@gmx.com> escreveu ----

On Wed, 25 May 2022 19:42:12 +0000 (UTC)
Hector Vido <hector_vido@yahoo.com.br> wrote:

> ... But I think this is
> explained in that way because of string concatenations. If you do
> something like this inside a loop: myName = myName .. 'blah'
> This will leave a lot of "new strings" in memory to be cleaned by
> the garbage collector, instead of just "replace" the value of
> "myName" variable.

Thank you Hector for your explanation.
I tested it in the Lua REPL:
myName = 'hector'
myName = myName .. ' vido'
print(myName) => hector vido

So the char array "myName" has a new value. Correct?
and there is now an abandoned char array that contain only 'hector'?
which the gc will eventually destroy?

--
Duke
** Bottom posting text only is the netiquette way! **