|
Boost Users : |
Subject: [Boost-users] serialization library leaks memory in its global object
From: gast128 (gast128_at_[hidden])
Date: 2009-11-30 08:11:20
Dear all,
we were transferring to Boost 1.41 but came across some serious issues in
Boost.Serialization.
The first is already adressed in a previous post, but now the M$ crt reports a
memory leak when using Boost.Serialization in combination of pointers. I think
it is located in 'basic_iarchive_impl::load_pointer' where an object is
allocated and added to a global object ('object_id_vector') but never
released.
I know that we might end up here in an argument about the defintion of a
memory leak, but the fact remains that the crt just reports it on program
closure and until now we never had any reports of that type. If we have to
think about every report dumped by the crt, it's just unacceptable. It's like
a broken window syndrome; in the end u can not distinguish between false and
correct reports.
Code:
#include <sstream>
#include <boost\smart_ptr\make_shared.hpp>
#include <boost\archive\xml_oarchive.hpp>
#include <boost\archive\xml_iarchive.hpp>
struct Foo
{
template <class Archive>
void serialize(Archive& /*ar*/, const unsigned int /*version*/)
{
}
};
int main()
{
#ifdef _DEBUG
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF |
_CRTDBG_LEAK_CHECK_DF);
#endif
std::stringstream sstr;
boost::shared_ptr<Foo> ptrFoo = boost::make_shared<Foo>();
{
boost::archive::xml_oarchive oa(sstr);
oa << boost::serialization::make_nvp("v", ptrFoo);
}
boost::archive::xml_iarchive ia(sstr);
ia >> boost::serialization::make_nvp("v", ptrFoo);
return 0;
}
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