lua-users home
lua-l archive

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


On Tue, Aug 26, 2014 at 12:45:54AM +0200, Robert Virding wrote:
> OK, this is what I understood by pooling.
> 
> What I was wondering is that if you have a system where each new string is
> interned then the string table will keep growing with new strings. This
> does make for very fast checking of string equality. However, if you have
> dynamically created strings, for example data coming into the system from
> the outside, then the string table will grow and eventually crash the
> system.

Strings are garbage collected just like any other object. All string
interning does it make sure that there exists only one copy of a string in
the VM. So in every conceivable scenario Lua will use no more memory than
with non-interned strings, and typically much less memory, even in the case
when you're generating many temporary strings.

In Java strings are immutable so that they can be interned as an
optimization. All compile-time constant strings in Java are interned.

Memory bloat can be an issue in Lua (and Java!) not because of string
interning, but because of immutable strings. This is less of an issue in Lua
than Java because in Lua all strings are interned, which minimizes the
number of unique string objects. But much like Java the idiomatic
"workaround" when it does become a problem is to implement a buffer object,
e.g. Java's StringBuffer.

Lua 5.2 added a generational collector, which could help alleviate excessive
garbage strings by quickly collecting unused strings. However, in reality
nobody had much of an issue with bloat in this regard, at least not so much
that anybody bothered to speak up to prevent the generational collector from
being removed from 5.3.