|
Boost Users : |
Subject: Re: [Boost-users] [serialization] Memory leaks even with shared_ptrs
From: cc caprani (cc.caprani_at_[hidden])
Date: 2011-07-21 15:32:22
On Thu, Jul 21, 2011 at 4:26 PM, cc caprani <cc.caprani_at_[hidden]> wrote:
>
> <smacks forehead> Oh that could have nearly been embarrassing!
>
> Luckily I had actually done that in a previous test - the problem still
> remains when scoped correctly as suggested.
>
> Thanks for the input Maxine. <- apologies, Maxime.
>
After some more work on it, I realize that some of the leaks were
incorrectly reported by _CrtDumpMemoryLeaks(); as the BOOST_CLASS_EXPORT is
only tidied up as the program exits. The very last comment on this page is
key: http://msdn.microsoft.com/en-us/library/e5ewb1h3%28v=vs.80%29.aspx.
This very simple program still leaks one copy of everything loaded from the
archive.
The new main() for the previously posted code with improved leak detection
is:
int main()
{
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
// the file to read/save from/to
std::string file = "archive.xml";
// make some Parmeters
std::vector<ParameterPtr> vParam;
vParam.push_back( boost::make_shared<Parameter>(1,1) );
vParam.push_back( boost::make_shared<Parameter>(2,2) );
// display for checking
for(unsigned int i = 0; i != vParam.size(); ++i)
std::cout << "P: " << vParam.at(i)->getDist()->getType() <<
std::endl;
// save the file
std::cout << "Writing..." << std::endl;
save(vParam,file);
// clear it
vParam.clear();
// read the file
std::cout << "Reading..." << std::endl;
load(vParam,file);
// display for checking
for(unsigned int i = 0; i != vParam.size(); ++i)
std::cout << "P: " << vParam.at(i)->getDist()->getType() <<
std::endl;
std::cin.get(); // hold console window open
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