help-bison
[Top][All Lists]
Advanced

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

Re: Memory (de)allocation ...


From: Hans Aberg
Subject: Re: Memory (de)allocation ...
Date: Tue, 6 May 2003 14:43:57 +0200

At 09:53 +0200 2003/05/06, Akim Demaille wrote:
>|        I am developing a script language compiler using Flex (C++
>| classes generated) and Bison (%pure-parser directive used), that will
>| be running as a multi-threaded server process (in Win32). What should
>| I do in order to avoid memory leakage?
>|
>|     a) Manually write all deallocation code in every single action;
>|
>|     b) Use the following Bison syntax:
>|           %destructor { delete $$; } program
>|           %destructor { if ( $$.mem ) delete $$.mem; } items rule2
>|           %destructor { complexCode( $1 ); delete $$; } xpto_rule
>|           ...
>|
>|     Option b) should be the correct one, right!? In case of a syntax
>| error, the right destructors are always called. Am I correct?! Or am I
>| missing something.
>
>You are correct, this is the intention.  But IIRC there is still one
>case where we leak.  I can't remember the case though :(

One should only use the C parser stacks under C++ if one is sure that either:
1. One does not make use of non-trivial constructors in the stacked objects.
2. The parser stack is not recopied.

Point 1 is essentially the condition that the data types are (as defined in
the C++ standard) POD's (plain old data). If one makes use of the Bison
%union feature and it compiles under C++, then the semantic type only uses
POD's as other types are not allowed in C++ unions. So the condition 1
above is fulfilled.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]