[date_time] Memory leak in io example?

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?

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_castlocale::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.

On 1:59 PM, John Maddock wrote:
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_castlocale::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."
Thanks! And even Apache's docs are vindicated (http://stdcxx.apache.org/doc/stdlibref/locale.html#idx809), though I doubt I would have found it on my own.
participants (2)
-
Jim Bell
-
John Maddock