When is% destructor used in bison? I have the following bison code:
%union{ char * sval; Variable * vval; } %token VARIABLE %token Literal %type <vval> Expression VARIABLE %type <sval> Literal %destructor { delete $$; } <vval> %destructor { delete $$; } Literal
where Variable is the class. I thought that after processing the string, all Variable objects would be freed, but I do not see any destructor called. And this will directly lead to a memory leak ...
Edit: be clear; I allocate a new Variable object for the new token, and this token is pushed onto the BISON stack. I want to delete a variable when it is knocked out by a bison and removed from the stack. I thought that% destructor serves this purpose, but I'm not sure anymore.
source share