zaach / jison

Bison in JavaScript.
http://jison.org
4.36k stars 450 forks source link

[feature req] add `%destructor` support #345

Open GerHobbelt opened 7 years ago

GerHobbelt commented 7 years ago

Cf. https://www.gnu.org/software/bison/manual/html_node/Destructor-Decl.html (bison manual page about %destructor)

See also http://stackoverflow.com/questions/6401286/when-is-destructor-invoked-in-bison

%destructor is also very useful in JavaScript to prevent memory leaks when your lexer produces yylval token values (in jison, that would be in lexer.yytext ATM...) which are object instances which don't garbage collect easily (e.g. when they're part of an object reference cycle, which must be 'broken up' before the garbage collector will be able to do its job).