Boost logo

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

This very simple program still leaks one copy of everything loaded from the

The new main() for the previously posted code with improved leak detection

int main()

    // 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: " <<>getDist()->getType() <<

    // save the file
    std::cout << "Writing..." << std::endl;

    // clear it

    // read the file
    std::cout << "Reading..." << std::endl;
    // display for checking
    for(unsigned int i = 0; i != vParam.size(); ++i)
        std::cout << "P: " <<>getDist()->getType() <<

    std::cin.get(); // hold console window open
    return 0;

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at