Design Behavior.
Me : it must be a multi_pass iterator multi_pass . Since there is no grammar, the Spirit does not know when it can turn red. [...]
You : as I know, istream_iterator takes care of reading the input stream without having to store the entire stream in memory
Yes. But you are not using std::istream_iterator . You are using Boost Spirit. This is a parser generator. Parsers need random access for reverse tracking.
Spirit supports input iterators, adapting the input sequence to a random access sequence using the multi_pass adapter. This iterator adapter stores variable size buffer 1 for backtracking purposes. Some actions (waiting points, always greedy operators such as Kleene- * , etc.) tell the parser structure when it is safe to flush the buffer.
Problem:
You do not understand, just a marker. Nothing ever tells an iterator to flush its buffers.
The buffer is unlimited, so the amount of memory increases. Of course, this is not a leak, because as soon as the last copy of the adapter with the multi-pass adapter goes out of scope, the common backtracking buffer is freed.
Decision:
The easiest solution is to use a random access source. If you can, use a memory mapped file.
Other solutions include indicating the reset of a multi-pass adapter. The easiest way to achieve this is to use tokenize_and_parse . Even with fake grammar, such as *(any_token) , this should be enough to convince the parser structure, you wonβt ask her to return.
Inspiration:
ΒΉ http://www.boost.org/doc/libs/1_62_0/libs/spirit/doc/html/spirit/support/multi_pass.html stores a common detective by default. Look at it, checking the test a bit, using dd if=/dev/zero bs=1M | valgrind --tool=massif ./sotest dd if=/dev/zero bs=1M | valgrind --tool=massif ./sotest :

Clearly displays all memory in
100.00% (805,385,576B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc. ->99.99% (805,306,368B) 0x4187D5: void boost::spirit::iterator_policies::split_std_deque::unique<char>::increment<boost::spirit::multi_pass<std::istream, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::istream, boost::spirit::iterator_policies::split_std_deque> > >(boost::spirit::multi_pass<std::istream, boost::spirit::iterator_policies::default_policy<boost::spirit::iterator_policies::ref_counted, boost::spirit::iterator_policies::no_check, boost::spirit::iterator_policies::istream, boost::spirit::iterator_policies::split_std_deque> >&) (in /home/sehe/Projects/stackoverflow/sotest) | ->99.99% (805,306,368B) 0x404BC3: main (in /home/sehe/Projects/stackoverflow/sotest)