|
Boost : |
From: Sean Huang (huangsean_at_[hidden])
Date: 2006-02-17 14:16:04
I sent my first reply through a newsgroup reader but it seems it got lost
somewhere...
There is a bug in std::basic_iostream in VC8
(http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=e08bd793-3fef-40ff-adda-ed313e0eafcc)
that affects all classes derived from it. During the output of a ptime, a
basic_stringstream object is created/destroyed and that is causing the
memory leak. I personally think Microsoft should release a patch for this
but it looks like they won't until the next release. You might be able to
obtain a hotfix by contacting Microsoft Technical support.
On the other hand, std::basic_ostringstream/std::basic_istringstream do not
suffer the same memory leak. And maybe data_time library can change to use
them instead of std::basic_stringstream (line 304 in time_facet.hpp as of
release 1.33.0). I haven't really looked into data_time library so I can not
say this for sure.
HTH,
Sean
----- Original Message -----
From: "Alo Sarv" <alo.sarv_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Friday, February 17, 2006 12:46 PM
Subject: Re: [boost] [date_time] [MSVC8] Memory leak in operator<<(ptime)
> On 2/17/06, Jeff Garland <jeff_at_[hidden]> wrote:
>> Well, that's odd. The only place that date-time does an allocation is in
>> operator<< and operator>>. So there 'could' be a problem with leaking in
>> that
>> code -- either a bug in date-time code or standard library code.
>> However,
>> time_duration and posix_time use the exact same allocation techniques
>> (and
>> facet code) so should exhibit the exact same leaking behavior.
>> Basically,
>> what gets allocated is a custom date-time facet that gets imbued into the
>> stream. This gets done on the first call to operator>> or operator<< on
>> a
>> particular stream. After that it just uses the facet avoiding the
>> allocation.
>> The facet is written to work with C++ I/O streams which has a reference
>> counting and should destroy the facet when the stream is destroyed. In
>> the
>> case of std::cout this may be after main has exited.
>
> Yes, the first place I looked was that code as well, and thought
> perhaps the custom facet doesn't get destroyed properly. However, that
> facet is only created once, so that doesn't seem to be the cause,
> especially considering other operator<<'s also use basically the same
> code.
>
>> If you want to trace it thru you could explicitly create and delete a
>> stringstream and check it's behavior. The date-time code that does the
>> allocations is in date_time/posix_time/posix_time_io.hpp.
>
> These two snippets also exhibit the leakage (around 50-80kb/s):
>
> using namespace boost::posix_time;
> ptime p(second_clock::local_time());
>
> while (true) {
> std::ostringstream *o = new std::ostringstream;
> *o << p;
> delete o;
> }
>
> while (true) {
> std::ostringstream() << p;
> }
>
> So clearly it's not some kind of hidden std::cout buffering by the
> library that could've caused this. I also stepped through the entire
> call hiearchy of the operator<< in debugger but couldn't find anything
> of use / suspicious.
>
> I attempted to use Purify to trace the leakage further, but apparently
> (at least my version) can't understand the debug format of MSVC8, and
> I don't have older version of the compiler around right now. But it
> did display some 4000 bytes leaked, just didn't say from where.
>
> --
> Alo Sarv
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk