Boost logo

Boost Users :

Subject: Re: [Boost-users] [date_time] Memory leak in io example?
From: John Maddock (boost.regex_at_[hidden])
Date: 2011-02-17 11:34:05


> In the example code under Date Time Input/Output
> <http://www.boost.org/doc/libs/1_45_0/doc/html/date_time/date_time_io.html>,
> "A simple example of this new system:", it shows a date_facet being
> constructed with new, then a locale constructed with it, and finally
> ios::imbue called on that.
>
>>From what I can tell from locale's constructors
> <http://stdcxx.apache.org/doc/stdlibref/locale.html#idx811> and imbue,
> neither will own/release that pointer.
>
> True?

False I believe: all facet types derive from std::locale::facet, which is a
reference counted class. As long as the reference count starts off at 0
when the facet is constructed, and then to quote from "22.1.1.1.2":

"The refs argument to the constructor is used for lifetime management.
- For refs == 0, the implementation performs delete
static_cast<locale::facet*>(f)
(where f is a pointer to the facet) when the last locale object containing
the facet is destroyed; for
refs == 1, the implementation never destroys the facet."

HTH, John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net