From: John Millaway Date: Tue, 2 Jul 2002 19:47:15 +0000 (+0000) Subject: Added a faq. X-Git-Tag: flex-2-5-10~48 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1baa806fc697ed07909557177119e1fde4b47aec;p=flex Added a faq. --- diff --git a/faq.texi b/faq.texi index 110a243..c903f01 100644 --- a/faq.texi +++ b/faq.texi @@ -68,6 +68,7 @@ * Is there a way to make flex treat NULL like a regular character?:: * Whenever flex can not match the input it says "flex scanner jammed".:: * Why doesn't flex have non-greedy operators like perl does?:: +* Memory leak - 16386 bytes allocated by malloc.:: @end menu @@ -751,3 +752,29 @@ state), and perhaps (.|\n) to get a single character within the chunk ... This approach also has much better error-reporting properties. + +@node Memory leak - 16386 bytes allocated by malloc. +@unnumberedsec Memory leak - 16386 bytes allocated by malloc. + +The leak is ~16426 bytes. That is, (8192 * 2 + 2) for the read-buffer, and +about 40 for struct yy_buffer_state (depending upon alignment). The leak is in +the non-reentrant C scanner only (NOT in the reentrant scanner, NOT in the C++ +scanner). Since flex doesn't know when you are done, the buffer is never freed. + +However, the leak won't multiply since the buffer is reused no matter how many +times you call yylex(). + +If you want to reclaim the memory when you are completely done scanning, then +you might try this: + +@example +@verbatim +/* For non-reentrant C scanner only. */ +yy_delete_buffer(yy_current_buffer); +yy_init = 1; +@end verbatim +@end example + +Note: yy_init is an "internal variable", and hasn't been tested in this +situation. It is possible that some other globals may need resetting as well. +