jerryscript-project/jerryscript

gc for strings in jerryscript

godmiaozi opened this issue · 1 comments

will string be reclaimed when gc runs in jerryscript. how string will be managed when it is no longer needed. for example

function PrintHello() 
{
     var hello = "hello"
}
function main()
{
    PrintHello();
}

when PrintHello call in main finished, will "hello" be reclaimed if we do not have enough memory for new objects allocation

Hi @godmiaozi!

Defining no longer is needed is not that simple. First of all, "hello" string is not allocated in each invocation of the PrintHello function, it's stored in the function's literal pool as a constant. The parser uses the same string table for every function to prevent duplicated existence of static string constants all the string are alive until the engine is not terminated. So summarize, reclaiming the memory for static strings are not supported by the engine, however the dynamically allocated strings like "foo" + "bar" gets garbage collected when they are no longer needed of course.