
Gregory, Matthew <matt.gregory@oregonstate.edu> wrote:
Forgive the likely simple question ...
I am using boost-1.30.2 regex library in a C++ console app and have been using VC7 to debug memory leaks through the _CrtDumpMemoryLeaks() function.
Where is this called from?
It reports numerous memory leaks on the first time I use a boost::regex object, albeit relatively small leaks. For example, if I use
boost::regex statsRe("^\\s+8\\s+ENVI\\s+AX4.*")
there are a number of memory leaks from memory allocated in the boost::re_detail::w32_traits_base::do_init() block.
I am wondering if I am doing something wrong in that no destructor gets called for these objects or if small memory leaks are to be expected when using these objects.
The only memory allocation I can see is for the array that pclasses points to and the strings in it. These are freed in do_free() which is called by the destructor of the last instance of w32_traits_base. Since each of the derived classes of w32_traits_base (w32_regex_traits<char> and w32_regex_traits<wchar_t>) has a static instance of itself as a member, the memory will not be freed until after main() returns. So if you call _CrtDumpMemoryLeaks() at the end of main() this memory will wrongly be reported as leaked.